Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Valued Mentor
gccdaemon
Posts: 468
Registered: ‎09-14-2010
Message 1 of 8 (473 Views)
Accepted Solution

DXF Codes

473 Views, 7 Replies
05-13-2013 07:23 AM

I am creating a lisp routine to take a detail file and standardize it for insertion into multiple plan sets. One of the things i'm not sure of is if you can change the contents of a DXF code number or not. If so, how would I go about changing that data across a selection set? Sorry if this sounds LISP-noobish.

Andrew Ingram

Civil 3D x64 2012
Win 7 x64 Ultimate
I7 3820 (3.6ghz quad core with HT)
32gig RAM (Corsair XMS3 4x8g)
Intel x z79 mobo (BOXDX79TO 2011 socket)
Radeon HD 7850 2gb GDDR5

gccdaemon wrote:

I am creating a lisp routine to take a detail file and standardize it for insertion into multiple plan sets. One of the things i'm not sure of is if you can change the contents of a DXF code number or not. If so, how would I go about changing that data across a selection set? Sorry if this sounds LISP-noobish.


Yes, you can do that, for many entity data entries, though not all.  Here's an example, changing the Layer of all objects in a selection set to 0, with ss being a variable holding the selection set:

 

(repeat (sslength ss)

  (setq

    edata (entget (ssname ss 0)); entity data for first [remaining] object in set

    edata (subst '(8 . "0") (assoc 8 edata) edata); replace Layer entry in it

  ); setq

  (entmod edata); apply that

  (ssdel (ssname ss 0) ss); take that object out of set

); repeat

 

If you are going to need that same selection set to do something else with it, you would need to do it differently [there are many examples on this forum of stepping through a selection set with a counter, without removing things from it as you go along as the above does].

 

Depending on what you want to change, there may be a simpler way to do it than via DXF codes.  For example, the above could also be accomplished this way, doing all objects together instead of individually:

 

(command "_.chprop" ss "" "_layer" "0" "")

*Expert Elite*
Kent1Cooper
Posts: 5,872
Registered: ‎09-13-2004
Message 2 of 8 (458 Views)

Re: DXF Codes

05-13-2013 08:15 AM in reply to: gccdaemon

gccdaemon wrote:

I am creating a lisp routine to take a detail file and standardize it for insertion into multiple plan sets. One of the things i'm not sure of is if you can change the contents of a DXF code number or not. If so, how would I go about changing that data across a selection set? Sorry if this sounds LISP-noobish.


Yes, you can do that, for many entity data entries, though not all.  Here's an example, changing the Layer of all objects in a selection set to 0, with ss being a variable holding the selection set:

 

(repeat (sslength ss)

  (setq

    edata (entget (ssname ss 0)); entity data for first [remaining] object in set

    edata (subst '(8 . "0") (assoc 8 edata) edata); replace Layer entry in it

  ); setq

  (entmod edata); apply that

  (ssdel (ssname ss 0) ss); take that object out of set

); repeat

 

If you are going to need that same selection set to do something else with it, you would need to do it differently [there are many examples on this forum of stepping through a selection set with a counter, without removing things from it as you go along as the above does].

 

Depending on what you want to change, there may be a simpler way to do it than via DXF codes.  For example, the above could also be accomplished this way, doing all objects together instead of individually:

 

(command "_.chprop" ss "" "_layer" "0" "")

Kent Cooper
Valued Mentor
alanjt_
Posts: 483
Registered: ‎08-25-2008
Message 3 of 8 (454 Views)

Re: DXF Codes

05-13-2013 08:20 AM in reply to: gccdaemon

Here's a brokendown example on how to change the layer of a single entity to the current layer.

 

(defun c:Test (/ entity entitydata layerassoc currentlayer)

  (if (setq entity (car (entsel "\nSelect object to move to current layer: ")))
    (progn
      (setq currentlayer (cons 8 (getvar 'CLAYER)) ; new layer
            entitydata   (entget entity) ; selected entity's data
            layerassoc   (assoc 8 entitydata) ; selected entity's layer at the moment
      )

      (entmod ; make change take place
        (subst ; substitute entity's layer for the drawing's current layer
          currentlayer
          layerassoc
          entitydata
        )
      )
    )
  )
  (princ)
)

 

Valued Mentor
gccdaemon
Posts: 468
Registered: ‎09-14-2010
Message 4 of 8 (450 Views)

Re: DXF Codes

05-13-2013 08:25 AM in reply to: gccdaemon

I can do the basics with commands, but i need to delve into changing font names and "Z" values as well globally after filtering my selection to object specific selection sets, and a lot of the properties i'm looking at are not covered in chprop.

Andrew Ingram

Civil 3D x64 2012
Win 7 x64 Ultimate
I7 3820 (3.6ghz quad core with HT)
32gig RAM (Corsair XMS3 4x8g)
Intel x z79 mobo (BOXDX79TO 2011 socket)
Radeon HD 7850 2gb GDDR5
*Expert Elite*
Kent1Cooper
Posts: 5,872
Registered: ‎09-13-2004
Message 5 of 8 (442 Views)

Re: DXF Codes

05-13-2013 09:16 AM in reply to: gccdaemon

gccdaemon wrote:

.... i need to delve into changing font names and "Z" values as well globally after filtering my selection to object specific selection sets, and a lot of the properties i'm looking at are not covered in chprop.


Font names for Text/Mtext/Dimensions can be changed via changing their Style in the same way as changing the Layer above [using the 7 code instead of the 8 code], or using equivalent VLA methods to replace the StyleName property.  Bear in mind that Mtext could give you other problems, since fonts can be overridden within it -- Search for a routine called [I think] StripMtext for a way to remove all internal overrides.

 

Or, you may be able to simply redefine a Style [for Text/Mtext, with the Style command or via (subst)/(entmod) on the Style's definition from (entget (tblobjname "style" ...)); or for Dimension Styles similarly], to change the font of all Text/Mtext/Dimension/etc. objects that use that Style. 

 

How you would do Z-value things would depend on the entity type, and in some cases on other considerations [for example, for a LIne that may have its ends at different elevations, or for a 3D Polyline, would you want both ends or all vertices to be forced to the same Z coordinate, or would you want to move the whole object so that, for instance, its start point is at that elevation, but otherwise leave it unchaged?].  For some things, you might be able to just use Move, substituting the Z value you want into the insertion or other reference point.  You can also use (subst)/(entmod) or VLA methods similarly to replace insertion points and the like.

Kent Cooper
Valued Mentor
gccdaemon
Posts: 468
Registered: ‎09-14-2010
Message 6 of 8 (428 Views)

Re: DXF Codes

05-13-2013 11:19 AM in reply to: Kent1Cooper

I have stripmtext already, lol. So subst changes the dxf code string? and that does apply to all items in the selection set that have that common dxf code?

Andrew Ingram

Civil 3D x64 2012
Win 7 x64 Ultimate
I7 3820 (3.6ghz quad core with HT)
32gig RAM (Corsair XMS3 4x8g)
Intel x z79 mobo (BOXDX79TO 2011 socket)
Radeon HD 7850 2gb GDDR5
*Expert Elite*
Kent1Cooper
Posts: 5,872
Registered: ‎09-13-2004
Message 7 of 8 (414 Views)

Re: DXF Codes

05-13-2013 12:38 PM in reply to: gccdaemon

gccdaemon wrote:

.... So subst changes the dxf code string? and that does apply to all items in the selection set that have that common dxf code?


It won't do it to all of them at once, but you need to step through the set -- that's why the (repeat) function is used in my first post, though there are other approaches [you can do it with (while), or, if you convert the selection set to a list of entity names, with (foreach)].  That's why the (command) approach can sometimes be easier if you're changing the same kind of thing about multiple entities, such as their Layer in my example.

 

What (subst) does is [as you might expect] SUBSTitute one thing for another in a list -- any kind of thing in any kind of list.  When that list is entity data, and the things involved are entity data sub-lists, and the one you're substituting in to replace another is constructed correctly, then yes, it changes the information associated with the relevant DXF code number [your use of the word "string" is potentially confusing, since not all entries involve Strings as AutoLISP defines the word].  The same can usually be done with VLA functions such as (vla-put) using VLA properties.  You need to convert the entity into a VLA object to use those on it, but if you're changing multiple properties of an object, or have a reason to also use other VLA functions on it, it's probably worth the "overhead" to make that conversion.  It can also be worth it in the case of certain properties that are a lot easier to extract that way than from entity data lists [one example -- the coordinates of the vertices of a 2D "heavy" or 3D Polyline], or it can even be necessary for certain information [e.g. to find an entity's bounding box].

 

You can find many examples of the various approaches on the forum with a Search.  If you describe a specific circumstance, someone can probably show you how to do it for that, or link you to an example, and you should be able to use that as a basis for working out ways to handle other circumstances.

Kent Cooper
Valued Mentor
gccdaemon
Posts: 468
Registered: ‎09-14-2010
Message 8 of 8 (406 Views)

Re: DXF Codes

05-13-2013 01:10 PM in reply to: gccdaemon

This points me in the right direction. Thanks for the assist fellas. Kudos to all involved.

Andrew Ingram

Civil 3D x64 2012
Win 7 x64 Ultimate
I7 3820 (3.6ghz quad core with HT)
32gig RAM (Corsair XMS3 4x8g)
Intel x z79 mobo (BOXDX79TO 2011 socket)
Radeon HD 7850 2gb GDDR5
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.