Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp goes into Endless loop

3 REPLIES 3
Reply
Message 1 of 4
Jeff Cook
262 Views, 3 Replies

Lisp goes into Endless loop

Can anyone help fix this lisp? What I am trying to do is search for all text objects and blocks on the defpoints layer and change their plotstylename to ByLayer. I would also like to change the lineweight to ByLayer.

As this thing is written now, it gets to the part about changing the text to ByLayer for plotstyle and Default for Lineweight then enters an endless loop. I am pretty new to this stuff in general, and this is the first time I've tried to include vla statements in anything I've done. Any help would be greatly appreciated.

Thank you so much.

Jeff

Below is my lisp.

BTW I copied a lot of this from other peoples posts, so some of it may not be needed. I'm not sure if I need especially the (vla-startundomark acad) line. I'm not totally sure what that line and the endundomark do for me.


(DEFUN C:testFIXCLR (/ NUMB3 SS3 OBJ numb4 ss4)
(setvar "cmdecho" 0)
(setq numb3 -1)
(if
(setq ss3 (ssget "X"
'((8 . "DEFPOINTS")
(62 . 176)
)
)
)

(repeat (sslength ss3)
(setq numb3 (1+ numb3))
(setq obj (entget (ssname ss3 numb3)))
(setq obj (subst (cons 62 256) (assoc 62 obj) obj))
(entmod obj)
)
)
(vl-load-com)
(setq acad (vlax-get-acad-object)
doc (vla-get-activedocument acad)
)
(vla-startundomark acad)
(cond
(setq
ss4
(ssget "X"
'((8 . "DEFPOINTS")
(0 . "text")
)
)
)
(setq numb4 0)
(repeat
(sslength ss4)
(setq item (vlax-ename->vla-object (ssname ss4 numb4)))
(vlax-put-property item "PlotStyleName" "ByLayer")

(vlax-put-property item "Lineweight" acLnWtByLwDefault)
(vlax-release-object item)
(setq numb4 (1+ numb4))
)
)
(vla-endundomark acad)
(setq acad (vlax-get-acad-object)
doc (vla-get-activedocument acad)
)
(vla-startundomark acad)
(cond
(setq
ss4
(ssget "X"
'((8 . "DEFPOINTS")
(0 . "block")
)
)
)
(setq numb4 0)
(repeat
(sslength ss4)
(setq item (vlax-ename->vla-object (ssname ss4 numb4)))
(vlax-put-property item "PlotStyleName" "ByLayer")

(vlax-put-property item "Lineweight" acLnWtByLwDefault)
(vlax-release-object item)
(setq numb4 (1+ numb4))
)
)
(vla-startundomark acad)
(setvar "cmdecho" 1)
(princ)
)
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Jeff Cook

Jeff Cook wrote:
> Can anyone help fix this lisp? What I am trying to do is search for all text objects and blocks on the defpoints layer and change their plotstylename to ByLayer. I would also like to change the lineweight to ByLayer.
>
> As this thing is written now, it gets to the part about changing the text to ByLayer for plotstyle and Default for Lineweight then enters an endless loop. I am pretty new to this stuff in general, and this is the first time I've tried to include vla statements in anything I've done. Any help would be greatly appreciated.
>


>
> (cond
> (setq
> ss4
> (ssget "X"
> '((8 . "DEFPOINTS")
> (0 . "block")
> )
> )
> )
>

Regardless of what else is wrong, at least your COND statements are
screwed up. Here your test clause is the symbol SETQ, not the expression
(setq ss4 ...).

As SETQ evaluates to # or something like that,
which is not NIL, the rest of the expressions will always be executed.

Try this with (cond ((setq ss4 ...)))

--
Message 3 of 4
Jeff Cook
in reply to: Jeff Cook

Thanks, I'll see if I can make it go with that.
Message 4 of 4
Jeff Cook
in reply to: Jeff Cook

So, I fixed the setq thing, now it kind of works, but not really. I can watch it go through the motions, I think I have the repeat part messed up on the existing one.

I tried again last night with a slightly different method. It seems to work the way I want it to. Thanks for your help.

Jeff

BTW If anyone wants to see the one that works, it is below and the attached file.

(defun c:testclr (/ ssets acadDocument newsset
ctr item filter_code filter_value
)

(setvar "cmdecho" 1)

;load the visual lisp extensions
(vl-load-com)

;retrieve a reference to the documents object
(setq acadDocument
(vla-get-activedocument
(vlax-get-acad-object)
)
)

;retrieve a reference to the selection sets object
(setq ssets (vla-get-selectionsets acadDocument))
;add a new selection set
(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list ssets "ss1")))

(setq newsset (vla-add ssets "ss1"))

(progn

(vla-delete (vla-item ssets "ss1"))

(setq newsset (vla-add ssets "ss1"))

);progn

);if

(setq filter_code (vlax-make-safearray vlax-vbinteger '(0 . 0)))

;create a single element array for the value
(setq filter_value (vlax-make-safearray vlax-vbvariant '(0 . 0)))

;DXF Code for layers
(vlax-safearray-fill filter_code '(8))

;the filter value
(vlax-safearray-fill filter_value '("Defpoints"))

;select ALL Blocks or Text on Defpoints

(vla-select newsset acSelectionSetAll nil nil filter_code filter_value)
;set the counter to zero
(setq ctr 0)

;count the number of objects and loop
(repeat (vla-get-count newsset)

;retrieve each object
(setq item (vla-item newsset ctr))

;check if the entity has a color property
;and it can be updated
(setq check (vlax-property-available-p item "PlotStyleName" T))


;if it can
(if check

;change it's color
(vlax-put-property item 'PlotStyleName "ByLayer")

) ;if
;check if the entity has a color property
;and it can be updated
(setq check1 (vlax-property-available-p item "Lineweight" T))


;if it can
(if check1


;change it's color
(vlax-put-property item 'LineWeight acLnWtByLayer
)

) ;if


;increment the counter
(setq ctr (1+ ctr))

) ;repeat



(princ)

) ;defun

(princ)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost