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

DXF Codes

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
gccdaemon
1273 Views, 7 Replies

DXF Codes

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 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
7 REPLIES 7
Message 2 of 8
Kent1Cooper
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, AIA
Message 3 of 8
alanjt_
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)
)

 

Message 4 of 8
gccdaemon
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 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
Message 5 of 8
Kent1Cooper
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, AIA
Message 6 of 8
gccdaemon
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 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
Message 7 of 8
Kent1Cooper
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, AIA
Message 8 of 8
gccdaemon
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 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram

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

Post to forums  

Autodesk Design & Make Report

”Boost