Change Polyline Global Width with LISP

Change Polyline Global Width with LISP

Anonymous
Not applicable
5,505 Views
10 Replies
Message 1 of 11

Change Polyline Global Width with LISP

Anonymous
Not applicable

I would like to incorporate a function into my existing routine that selects all of the polylines and sets them to a global width of 2.  I'm about new as they come to writing lisp coding so I figured I'd enlist the help of the pros.  My existing routine is below.  This centers the drawing, sends all hatch to the back, selects all text and changes it to legend. Now all I need is to add the polyline global width coding.  

 

(defun c:minex ()
(command"_ZOOM""_E")
	;zooms to extents
(command"_HATCHTOBACK")
	;sends all hatching to back of drawing order
(if (setq tss (ssget "_X" '((0 . "*TEXT"))))
(repeat (setq n (sslength tss))
(setq tdata (entget (ssname tss (setq n (1- n)))))
(entmod (subst '(7 . "LEGEND") (assoc 7 tdata) tdata))
); repeat
); if
); defun
(if (setq ss (ssget "_x" '((0 . "*TEXT"))))
        (repeat (setq i (sslength ss))
            (setq ent (entget (ssname ss (setq i (1- i)))))
            (entmod (subst (cons 40 150) (assoc 40 ent) ent))
        )
   (princ)
)

 

0 Likes
Accepted solutions (2)
5,506 Views
10 Replies
Replies (10)
Message 2 of 11

Ranjit_Singh
Advisor
Advisor

Here's one way of doing it

(mapcar '(lambda (x) (vla-put-constantwidth x 2)) (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "*POLYLINE")))))))
Message 3 of 11

Anonymous
Not applicable

I copied and pasted that into the existing routine and something isn't right.  I get a syntax error.  Here's where I put it in the routine, tell me if I'm not inserting on the correct line.

 

(defun c:minex ()
(command"_ZOOM""_E")
	;zooms to extents
(command"_HATCHTOBACK")
	;sends all hatching to back of drawing order
(if (setq tss (ssget "_X" '((0 . "*TEXT"))))
(repeat (setq n (sslength tss))
(setq tdata (entget (ssname tss (setq n (1- n)))))
(entmod (subst '(7 . "LEGEND") (assoc 7 tdata) tdata))
); repeat
); if
); defun
(if (setq ss (ssget "_x" '((0 . "*TEXT"))))
        (repeat (setq i (sslength ss))
            (setq ent (entget (ssname ss (setq i (1- i)))))
            (entmod (subst (cons 40 150) (assoc 40 ent) ent))
        )
(mapcar '(lambda (x) (vla-put-constantwidth x 2)) (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "*POLYLINE")))))))
   (princ)
)
0 Likes
Message 4 of 11

Ranjit_Singh
Advisor
Advisor
Accepted solution
(defun c:minex ()
(command"_ZOOM""_E")
	;zooms to extents
(command"_HATCHTOBACK")
	;sends all hatching to back of drawing order
(if (setq tss (ssget "_X" '((0 . "*TEXT"))))
(repeat (setq n (sslength tss))
(setq tdata (entget (ssname tss (setq n (1- n)))))
(entmod (subst '(7 . "LEGEND") (assoc 7 tdata) tdata))
); repeat
); if
(if (setq ss (ssget "_x" '((0 . "*TEXT"))))
        (repeat (setq i (sslength ss))
            (setq ent (entget (ssname ss (setq i (1- i)))))
            (entmod (subst (cons 40 150) (assoc 40 ent) ent))
        ))
(mapcar '(lambda (x) (vla-put-constantwidth x 2)) (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "*POLYLINE")))))))
   (princ)
)
Message 5 of 11

SeeMSixty7
Advisor
Advisor
Accepted solution

@Ranjit_Singh was providing you with the code to change the Plines.

 

Your command is multiple parts and not a single command. I moved your double text mods into one if statement then added Ranjit's code for you after the text had been processed. This is Ranjit's Solution, I just cleaned up your code a little and moved his for you.

 

Good luck,

(defun c:minex ()
	(command"_ZOOM""_E");zooms to extents
	(command"_HATCHTOBACK");sends all hatching to back of drawing order
	(if (setq tss (ssget "_X" '((0 . "*TEXT"))))
		(repeat (setq n (sslength tss))
			(setq tdata (entget (ssname tss (setq n (1- n)))))
			(entmod (subst '(7 . "LEGEND") (assoc 7 tdata) tdata))
			(entmod (subst (cons 40 150) (assoc 40 ent) ent))
		); repeat
	); if
	(mapcar '(lambda (x) (vla-put-constantwidth x 2)) (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex (ssget "_x" '((0 . "*POLYLINE")))))))	
); defun
Message 6 of 11

Ranjit_Singh
Advisor
Advisor

Good point by @SeeMSixty7, much cleaner code. Also, don't forget to add a princ before closing out the function. The mapcar will fill your command window with quite a few nils.

Message 7 of 11

Kent1Cooper
Consultant
Consultant

Consider adding a provision to only do the Polyline width assignment if there are any Polylines in the drawing, as the code in Post 1 checks whether there's any Text before processing it.  That width assignment gives an error if there are no Polylines.  Maybe that doesn't matter if it's the last thing, but it would be a problem if any further processing is added, and could be trouble if you're running it on multiple drawings somehow.

Kent Cooper, AIA
Message 8 of 11

Ranjit_Singh
Advisor
Advisor

I agree. That's a good point. Maybe something like this

(ssget "_x" '((0 . "*polyline")))
(vlax-for i (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
(vla-put-constantwidth i 2))

or

 

(and (setq ss1 (ssget "_x" '((0 . "*polyline"))))
(mapcar '(lambda (x) (vla-put-constantwidth x 2)) (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss1)))))
0 Likes
Message 9 of 11

john.uhden
Mentor
Mentor

Beware.  It will also error out if 3D polylines are selected (0 . "*POLYLINE").

 

You had better refine the filter...

 

(setq filter (list (cons 0 "*POLYLINE")(cons -4 "<NOT")(cons -4 "&")(cons 70 (+ 8 16 32 64))(cons -4 "NOT>")))

 

which can be shortened via a single quote in the right place.

John F. Uhden

0 Likes
Message 10 of 11

Ranjit_Singh
Advisor
Advisor

Correct. Other option would be to check if the property constantwidth is available. I m not on my computer so cannot verify but I believe 3dp does not have constantwidth property. 

0 Likes
Message 11 of 11

john.uhden
Mentor
Mentor

I had responded earlier today, but I guess it didn't get there.

 

You are correct.  Checking for the availability of the constantwidth property would allow for the selection of anything.

 

Keep your paint brushes clean; good ones are too expensive to just throw away.

John F. Uhden

0 Likes