AutoCAD script skipping portions of Autolisp Command

AutoCAD script skipping portions of Autolisp Command

CSM_MAI
Advocate Advocate
1,976 Views
8 Replies
Message 1 of 9

AutoCAD script skipping portions of Autolisp Command

CSM_MAI
Advocate
Advocate

I have a lip routine that will insert a stamp onto a drawing. When activated, it first looks for the stamp within the drawing to make sure it's not there, and if it doesn't find it, the routine will insert a stamp at a designated coordinate. I can type in this command and it will work all day. It will insert the stamp the first time the command is ran, and then it will notify the user that the stamp is already on the drawing the second time it's ran. I can keep tying this command in, and it will still keep notifying the User that the stamp is on the drawing until I delete the stamp out and run it again. That's how I want it to work. If I add this command to a script, It skips the portion where it looks for the stamp, and just inserts a new stamp on top of the existing stamp. I'm at a loss as to why it would work typing the command in manually but not work when ran from a script file. Any help on this would be greatly appreciated. 

0 Likes
Accepted solutions (1)
1,977 Views
8 Replies
Replies (8)
Message 2 of 9

cadffm
Consultant
Consultant

"It skips the portion where it looks for the stamp"

How can we help without knowing your code?

 

I am sure, it is looking for but not find them.

Post you snipped and you get help in detail.

Sebastian

0 Likes
Message 3 of 9

CSM_MAI
Advocate
Advocate

Below is a smaller version of what i'm working with, but the function is the same.

 

It looks for a border first to figure out what scale and location of the stamp, then based on what border it finds, it activates separate defun below. Once the onf of the bdr1 or bdr2 defuns are activated, it looks for the stamp, if it finds a stamp, it displays a message in the command line. If it doesn't not find a stamp, it will insert the stamp based on the information stored from main function.

 

It works fine with deciding what border to look for, but when it gets to the subfuncitons, it skips the part where it looks for the stamp and pastes a new stamp on top of the old one. 

 

;;;_________________________________________________________________________________________________________________________________;;;
(defun c:stampinsert ()
(command "limits" "off")
(setvar "cmdecho" 0)
(if (setq bdr (ssget "_X" '((2 . "border1,border2")))); selects border
(progn
(setq ename (cdr (assoc 2 (entget (ssname (ssget "P") 0)))))
(setq ins (cdr (assoc 10 (entget (ssname (ssget "P") 0)))))
(setq scl (cdr (assoc 41 (entget (ssname (ssget "P") 0)))))
(setq etypelist (list ename)); gets entity name
(setq elist (car etypelist)); converts entity name to list item
(setq slist (strcat elist))
(cond
((= slist "BORDER1") (bdr1))
((= slist "BORDER2") (bdr2))
); end cond
)
(progn
(princ "\n Standard border not present...")
)
);end if
(princ)
)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun bdr1 ()
(if (ssget "_X" '((2 . "stamp")))
(progn
(princ "\nStamp already on drawing")             << this part is ignored
)
(progn
(setq scl1 (* scl 0.500))
(command "_insert" "*C:/.../.../.../.../.../.../.../stamp" ins scl1 "0")
(setq ss (ssget "_X" '((2 . "stamp"))))
(command "_.move" ss "" "Displacement" "-13.00,-0.8958,0.0")
)
);end if
(setq scl nil)
(setq ins nil)
(setq ename nil)
(princ)
)
;;; -------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+-----------+
(defun bdr2 ()
(if (ssget "_X" '((2 . "stamp")))
(progn
(princ "\nStamp already on drawing")             << this part is ignored
)
(progn
(setq scl1 (* scl 0.500))
(command "_insert" "*C:/.../.../.../.../.../.../.../stamp" ins scl1 "0")
(setq ss (ssget "_X" '((2 . "stamp"))))
(command "_.move" ss "" "Displacement" "-15.25,-1.202,0.0")
)
);end if
(setq scl nil)
(setq ins nil)
(setq ename nil)
(princ)
)

0 Likes
Message 4 of 9

cadffm
Consultant
Consultant

Is CLIPROMPTUPDATE helping?

 

Sebastian

0 Likes
Message 5 of 9

CSM_MAI
Advocate
Advocate

CLIPROMPTUPDATE is set to 1. A little more information, I did some testing a minute ago. The stamp that gets inserted has visibility states to it. If I insert the stamp and do not change the visibility state, it wont insert a new stamp if I run the command from AutoCAD or script. If I change the visibility state to something other than the default visibility state, It will insert in a new block.

0 Likes
Message 6 of 9

ronjonp
Advisor
Advisor
Accepted solution

You can't filter by block name if you've modified the dynamic block. It changes it to an anonymous block name '*U*' You will need to iterate all blocks and look at the effectivename property, or filter by an insertion point if it's not shared with another block.

Message 7 of 9

CSM_MAI
Advocate
Advocate

That was it. I appreciate the info. I couldn't rely on the insertion point, so the selection by the effective name property was my solution. I appreciate it. This link provided some good information. 

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/block-s-effective-name-conflicts-wit...

0 Likes
Message 8 of 9

ronjonp
Advisor
Advisor

Glad you got it sorted.

 

I'm surprised your code works  .. it should bonk out at '(setq scl1 (* scl 0.500))' since 'scl' is never defined.

FWIW...2018-04-30_14-40-46.png

0 Likes
Message 9 of 9

CSM_MAI
Advocate
Advocate

I appreciate the tip. I will work on that. 

0 Likes