Help to change the code in the attached lisp file to select multiple objects

Help to change the code in the attached lisp file to select multiple objects

Anonymous
Not applicable
1,199 Views
4 Replies
Message 1 of 5

Help to change the code in the attached lisp file to select multiple objects

Anonymous
Not applicable

The lisp reduces linetype scale of objects by a given factor. I need help to select multiple objects. Right now the lisp selecting single object only.

0 Likes
Accepted solutions (1)
1,200 Views
4 Replies
Replies (4)
Message 2 of 5

SeeMSixty7
Advisor
Advisor

I'm not a big fan of changing individual objects linetype scales, but I do not know your application for it. Typically this should be done with LTSCALE. at the entity level it can become a real headache for anyone referencing your drawing files to get their linetypes to look correctly.

 

Now that that is out of the way. You have two options.

1. Highlighting the object in question and just using the Properties dialog is pretty efficient at completing the task you are wanting. This would apply same ltscale to all selected. so you would want to select all the ones with the same ltscale.

 

2. If you want to learn how to update this lisp file to handle multiple entities, then start with the following.

 

Since you want to apply a scale factor to each individual entities current LTScale, you will need to step through each one.

Start with getting a selection set

(setq myss (ssget))

then check if it is empty

(if (myss

 

next you will need to step through all the entities and change their ltscale, but first you need to prompt for the scale to apply to each.

(progn

  (setq myscalefactor (getreal "\nScale Factor to apply: ") ; get your scale factor

          mynuments (sslength myss)  ; how many entities to modify

         mycnt 0 ; entity counter

 )

now start a while loop or some other loop method to step through the selection set

(while (< mycnt mynuments)

  (setq myentdata (entget (ssname myss mycnt))

          myentltscale (assoc 48 myentdata)

  )

Trick here is to see if it exists ltscale at 1.0 means it is defaulted and does not exist so we will have to add if not

(if myentltscale

   (setq newltscale (* (cdr myentltscale) myscalefactor) ; apply scale to current ltscale

        newltscale (cons 48 newltscale) ; create the dxf entry for the new scale factor

        myentdata (subst newltscale myentltscale myentdata) ; substitute the new value for the old value

   )

   (setq myentdata (append myentdata (list (cons 48 myscalefactor)))) ; just create a dxf value for the ltscale

)

(entmod myentdata) ; update the entity

(setq mycnt (1+ mycnt)) ; bump our counter

)

 

wrap that all in a defun statement and you should be good to go.

 

Good luck

 

        

 

 

Message 3 of 5

ВeekeeCZ
Consultant
Consultant

Unlike @SeeMSixty7 I am big fan of changing LT scale. 🙂 So I made this routine kind for myself - which I was planning to do a long time.

 

It excludes entities with Continuous linetype (defined by layer or object property).

 

(defun c:LTScale ( / ss rc i ed)
  
  (if (and (setq ss (ssget ":L"))
	   (setq rc (getreal "\nPercentage of current scale (100=current): "))
	   )
    (repeat (setq i (sslength ss))
      (setq ed (entget (ssname ss (setq i (1- i)))))
      (if (not (or (and (not (assoc 6 ed))
			(= "Continuous" (cdr (assoc 6 (tblsearch "LAYER" (cdr (assoc 8 ed)))))))
		   (= "Continuous" (cdr (assoc 6 ed)))))
	(entmod (append ed
			(list (cons 48 (* (if (assoc 48 ed)
					    (cdr (assoc 48 ed))
					    1)
					  rc 0.01))))))))
  (princ)
)
0 Likes
Message 4 of 5

john.uhden
Mentor
Mentor

Umm, might you need to (command "_.undefine" "LTScale")?

John F. Uhden

Message 5 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

@john.uhden wrote:

Umm, might you need to (command "_.undefine" "LTScale")?


Thanks John. Bad name.

 

(defun c:LTScaleR ( / ss rc i ed)
  
  (if (and (setq ss (ssget ":L"))
	   (setq rc (getreal "\nPercentage of current scale (100=current): "))
	   )
    (repeat (setq i (sslength ss))
      (setq ed (entget (ssname ss (setq i (1- i)))))
      (if (not (or (and (not (assoc 6 ed))
			(= "Continuous" (cdr (assoc 6 (tblsearch "LAYER" (cdr (assoc 8 ed)))))))
		   (= "Continuous" (cdr (assoc 6 ed)))))
	(entmod (append ed
			(list (cons 48 (* (if (assoc 48 ed)
					    (cdr (assoc 48 ed))
					    1)
					  rc 0.01))))))))
  (princ)
)