TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andrew_nao on July 07, 2009, 04:12:16 PM
-
hello experts
would anyone know why this code wouldnt work at startup?
or maybe have a better way to explode all mtext in a dwg upon opening.
this is placed in my acaddoc.lsp it shows as it being loaded but doesnt do what it supposed to, which is explode all mtext when it loads
(defun s::startup ()
(if ss (ssget "x" '((0 . "mtext")))
(progn
(setvar "qaflags" 1)
(command ".explode" "p" "")
(setvar "qaflags" 0)
)
)
(princ)
)
thanks for any and all help
-
Give this a try:
(defun c:kaboomkaboom? (/ ss)
(if (setq ss (ssget "x" '((0 . "mtext"))))
(progn (setvar "qaflags" 1) (command ".explode" ss "") (setvar "qaflags" 0))
)
(princ)
)
;;Need to call the lisp
(c:kaboomkaboom?)
-
(defun s::startup ()
(if ss (ssget "x" '((0 . "mtext")))
(progn
(setvar "qaflags" 1)
(command ".explode" "p" "")
(setvar "qaflags" 0)
)
)
(princ)
)
[/code]
Could be you missed (Setq...
-
@ ron, it doesnt work that way either i tried that and was suggested to put it in s::startup
@ lee no setq shouldnt be needed. it works when loaded manually
so the there is nothing wrong with the code. it just wont load at startup
-
@ lee no setq shouldnt be needed. it works when loaded manually
so the there is nothing wrong with the code. it just wont load at startup
Of course if loads, as the ' if ' statement is a valid one, but the code won't do what you think it should be. If you run the code without a global variable ' ss ' then the code will try and explode the previous selection set, but if ' ss ' is defined, it will only select all mtext entities, then end the code. Lee makes a good point.
-
@ ron, it doesnt work that way either i tried that and was suggested to put it in s::startup
@ lee no setq shouldnt be needed. it works when loaded manually
so the there is nothing wrong with the code. it just wont load at startup
Works fine here? :?
-
I'm with Tim.
(defun s::startup ()
(if ss
(ssget "x" '((0 . "mtext")))
(progn
(setvar "qaflags" 1)
(command ".explode" "p" "")
(setvar "qaflags" 0)
)
)
(princ)
)
The code does this:
Check for variable ss
If ss exist get a selection set of ALL mtext in the drawing & exit
if ss is nil then explode the Previous Object(s)
The problem with Ron's version is that ssget ALL mtext in the drawing & then execute a COMMAND witch
I think will not work unless you feed it mtext in the current space.
Off to test this... 8-)
-
In my test the explode does work for mtext in the current space & ignores mtext not in current space.
Tested in ACAD2000
-
ok so even if i still change it to what lee suggested, i still cant get this to execute when a dwg is opened.
-
what file are you putting the code in?
-
...
The problem with Ron's version is that ssget ALL mtext in the drawing & then execute a COMMAND witch
I think will not work unless you feed it mtext in the current space.
Off to test this... 8-)
Picky picky :-P
(defun c:kaboomkaboom? (/ ss n)
(vl-load-com)
(setq n -1)
(if (setq ss (ssget "_x" '((0 . "MTEXT"))))
(setq n -1)
(while (setq e (ssname ss (setq n (1+ n))))
(vl-catch-all-apply 'vla-explode (list (vlax-ename->vla-object e)))
)
)
(princ)
)
;;Need to call the lisp
(c:kaboomkaboom?)
Apparently vla-explode does not work with MTEXT.....I give up :-D
-
Apparently vla-explode does not work with MTEXT.....I give up :-D
Yeah, its pretty annoying ;-)
-
With every new release the behaviour of existing commands may change. So when certain commands (for example EXPLODE) are issued in the Lisp routine, they may not behave as in previous version. The workaround is to add (initcommandversion 2) before the command is called. You can try this:
(defun s::startup ()
(if (ssget "X" '((0 . "MTEXT")))
(progn
; (setvar "qaflags" 1)
[color=red](initcommandversion 2)[/color]
(command "._explode" "P" "")
; (setvar "qaflags" 0)
)
)
(princ)
)
BTW... I wonder why you are turning off the grips? If you start a new drawing it seems to me that nothing is selected...
-
Crank,
What version of ACAD was initcommandversion introduced?
-
Crank,
What version of ACAD was initcommandversion introduced?
I believe it was introduced in AutoCAD 2009
-
With every new release the behaviour of existing commands may change. So when certain commands (for example EXPLODE) are issued in the Lisp routine, they may not behave as in previous version. The workaround is to add (initcommandversion 2) before the command is called. You can try this:
(defun s::startup ()
(if (ssget "X" '((0 . "MTEXT")))
(progn
; (setvar "qaflags" 1)
[color=red](initcommandversion 2)[/color]
(command "._explode" "P" "")
; (setvar "qaflags" 0)
)
)
(princ)
)
BTW... I wonder why you are turning off the grips? If you start a new drawing it seems to me that nothing is selected...
thanks Crank ill give this a try
as for the qaflags i read that they are usefull if i wanted to explode a selection set. maybe i misunderstood it.
and for some reason if i were to run my original explode mtext code without the qaflags, my custom ddedit lisp wouldnt work properly
ill let ya know how this worked out
thanks again
adding the initcommandversion did the trick
thanks again
-
Keith is right: this was introduced with Acad2009 (though VLIDE shows the same built number as 2008...)
From the help:
(http://www.theswamp.org/lilly_pond/crank/initcommandversion.jpg)