Jump to content

Autolisp Help


Francisco Ervedal

Recommended Posts

I am a beginner in autocad and in urgent need of your help. What is the code in AutoLISP to select objects on a layer and change its properties (color, text height, layer, etc.). Thanks for your help.

Link to comment
Share on other sites

Welcome to CT! Hope you get what you're after here!

 

ssget is used to make a selection. Check the help on that (preferably open VLIDE type ssget, put the cursor on that word and press Ctrl+F1).

 

The "simplest" way to do it would be to have ssget select the entities you want and then send that to the change command. It's not necessarily the "best" solution, but gives a simple starting point for you:

(if (setq ss (ssget "_X" '((8 . "LayerName"))))
 (command "._CHANGE" ss "" "_Properties" "_Color" "ByLayer" "_Layer" "NewLayerName" "")
)

As for text height, that's a bit more complex. In lisp you can only modify one entity at a time, but you can set lisp to perform that modification for each entity in the selection set. For this you'll need to loop through the selection set, get the ename & dxf codes of each in turn. Substitute the 40 dxf code with the new height. Then use entmod to apply the change to the entity:

(setq pos 0)
(while (< pos (sslength ss))
 (setq ename (ssname ss pos))
 (setq dxfdata (entget ename))
 (if (eq (cdr (assoc 0 dxfdata)) "TEXT")
   (entmod (subst '(40 . 200.0) (assoc 40 dxfdata) dxfdata))
 )
 (setq pos (1+ pos))
)

You could do similar for the other properties as well. You'll need to look into the DXF help, each entity type has some different codes. That's why I put that if to check if the current entity extracted from the selection set is a TEXT entity - note you may need to modify to also work with MTEXT.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...