PDA

View Full Version : Ways to improve the code of the following...


clovis
2006-07-18, 04:49 PM
hello,
I'd like to improve the code of the following
(if (not echelle)(setq echelle (getvar "dimscale")))
(if (tblsearch "dimstyle" "1-1")
(progn
(command "-dimstyle" "r" "1-1")
(setvar "dimscale" echelle)
(setvar "dimlfac" 1)
(command "dim1" "save" "1-1" "y")
)
)
(if (tblsearch "dimstyle" "2-1")
(progn
(command "-dimstyle" "r" "2-1")
(setvar "dimscale" echelle)
(setvar "dimlfac" 0.5)
(command "dim1" "save" "2-1" "y")
)
)
(if (tblsearch "dimstyle" "4-1")
(progn
(command "-dimstyle" "r" "4-1")
(setvar "dimscale" echelle)
(setvar "dimlfac" 0.25)
(command "dim1" "save" "4-1" "y")
)
)
(if (tblsearch "dimstyle" "5-1")
(progn
(command "-dimstyle" "r" "5-1")
(setvar "dimscale" echelle)
(setvar "dimlfac" 0.2)
(command "dim1" "save" "5-1" "y")
)
)
(if (tblsearch "dimstyle" "10-1")
(progn
(command "-dimstyle" "r" "10-1")
(setvar "dimscale" echelle)
(setvar "dimlfac" 0.1)
(command "dim1" "save" "10-1" "y")
)
)
Any idea's
Thanks

[ Moderator Action = ON ] What are [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]

rkmcswain
2006-07-18, 05:27 PM
Here is iteration 1


(if (not echelle)(setq echelle (getvar "dimscale")))
(setq mylist (list "1-1" "2-1" "4-1" "5-1" "10-1"))
(foreach item mylist
(if (tblsearch "dimstyle" item)
(progn
(command "-dimstyle" "r" item)
(setvar "dimscale" echelle)
(setvar "dimlfac" (/ 1.0 (atoi (substr item 1 (vl-string-position 45 item)))))
(command "dim1" "save" item "y")
)
)
)

clovis
2006-07-18, 05:32 PM
Hello,
That -is- a better way but I was wondering if something with vl-..or vlx to avoid the (command.. is possible?
Thanks

rkmcswain
2006-07-18, 06:13 PM
That is why I put "Iteration 1"... :-)

I don't have time at the moment. If you can wait, I can post a few ideas or maybe someone else will chime in....

CAB2k
2006-07-18, 06:39 PM
Another twist.
Not tested!
(or echelle (setq echelle (getvar "dimscale")))
(mapcar
'(lambda (item)
(if (tblsearch "dimstyle" item)
(progn
(vl-cmdf "-dimstyle" "r" item)
(setvar "dimscale" echelle)
(setvar "dimlfac" (/ 1.0 (atoi (substr item 1 (vl-string-position 45 item)))))
(vl-cmdf "-dimstyle" "save" item "y")
)
)
)
(list "1-1" "2-1" "4-1" "5-1" "10-1")
)

clovis
2006-07-19, 09:13 AM
I don't want to monopolyze your time so
Thank to you all for this great effort !!

jwanstaett
2006-07-19, 05:06 PM
here the code to to do the 1-1 dim style you need to add the code for the other styles


(if (not echelle)
(setq echelle (getvar "dimscale")))
;;-------------------------------------
;;set up dimstyle 1-1
(if (setq ED (tblsearch "dimstyle" "1-1"))
(progn
(setq ed (subst (cons 40 echelle) (assoc 40 ed) ed))
;SET dimscale 40 dxf code for dimscale
(setq ed (subst (cons 144 1) (assoc 144 ed) ed))
;set dimlfac 144 dxf code for dimlfac
(entmod ED) ;UPDATE THE DIM STYLE
)
;;end of dimstyle 1-1
;;add in the other dimstyles
)

rkmcswain
2006-07-19, 05:51 PM
How about this one (a combination of what we have so far.....untested...)


(vl-load-com)
(setq ds (vla-get-dimstyles (setq doc (vla-get-activedocument (vlax-get-acad-object)))))
(or echelle (setq echelle (getvar "dimscale")))
(mapcar
'(lambda (item)
(and
(setq tmp (vla-item ds item))
(setvar "dimscale" echelle)
(setvar "dimlfac" (/ 1.0 (atoi (substr item 1 (vl-string-position 45 item)))))
(vlax-invoke-method tmp "CopyFrom" doc)
)
)
(list "1-1" "2-1" "4-1" "5-1" "10-1")
)

clovis
2006-07-20, 05:18 PM
Hello guys !
Thank to you jwanstaett
But even if you do modify the list of the dimstyle, it's not updated. and the "entity" should be updated with (maybe) entupd. But again, a dimstyle is not an entity so that's why I had to use (command "dim1" "save"..)

Thank to you rkmcswain
It works almost perfectly ;-)
the dimstyle in used is not completely updated (take a look with ddim and you'll see that the active dimstyle has a <style overrides> -> just change the active dimstyle for a while.

I used to try to update my routines towards VLAX to make the jump to Vb (or C++ when the IDE will be in Acad) but I hadn't enough time to master it. So you're way is also my way.

Thanks again guys
Bye