Lisp for auto incrementing values in object data for selected objects

Lisp for auto incrementing values in object data for selected objects

randycarrion235LPXM
Community Visitor Community Visitor
626 Views
4 Replies
Message 1 of 5

Lisp for auto incrementing values in object data for selected objects

randycarrion235LPXM
Community Visitor
Community Visitor

Good day, my people!

 

I am looking for a Lisp routine for a specific task that is a bit tedious. I have to set ADE object data for a number of objects (Mpolygons, Polylines, arcs & lines) using ADEATTACHDATA and then select each object and add incrementing values for one of the object data values named OBJECTID starting from 1. It can be a task having to select each object and changing the value when sometimes it can be up to 600 objects.

 

Can someone please help me craft a Lisp routine that when all the objects are selected, it changes the OBJECTID values for each object starting with value 1 and on, so that no object has the same value?

 

Thank you so much for time if you are reading this!

0 Likes
627 Views
4 Replies
Replies (4)
Message 2 of 5

АлексЮстасу
Advisor
Advisor

Hi, randycarrion235LPXM

 

It is better to move the topic about Object Data to the Map 3D forum - https://forums.autodesk.com/t5/autocad-map-3d-forum/bd-p/85.


The ODEDIT_SETID command from ODEDIT may help for your task. Unfortunately, ODEDIT is only valid in versions 2012-2020.

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

0 Likes
Message 3 of 5

ChicagoLooper
Mentor
Mentor

@randycarrion235LPXM 

You are posting in the Plain Vanilla AutoCAD Forum. It would be better to post this type of question in the Map3D Forum.

 

Using LISP is unnecessary, using Map3D or Civil3D is.

 

If you are dealing with Object Data (OD), then you must be running Map3D (or Civil3D), those are the only AutoCAD verticals capable of understanding OD. If you do NOT run M3D or C3D, then you won't be able to create object data nor will you be able to verify whether you've successfully generated the OD during the creation procedure.

 

While using M3D, you may use MAPEXPORT to export your linework to either SDF or shapefile format. Whether you like it or not, OBJECTID will be added to your exported file (might also be name FeatID or FeatureID instead of ObjectID). All Feature Data Objects (FDOs) must have what's known as a UNIQUE IDENTIFIER. It's what the ObjectID or FeatID does--it serves the purpose of the Unique Identifier. The unique identifier is an automatically assigned integer attached to each exported entity when using MAPEXPORT--no two entities of an SDF (or shapefile) will have the same unique ID.  

 

Once the SDF or shapefile is created, then you may use MAPIMPORT command to import (bring in) the SDF/shapefile back into modelspace. The MapImport command will 'convert' the FDO file into  plain vanilla objects. You'll end up with plain vanilla entities when MapImport is completed successfully.

 

Using MapImport and know-how, the MapImport process will do the following:

  1.  Convert an FDO type of file into plain vanilla AutoCAD entities.
  2. Allow you to attach a unique identifier to each individual plain vanilla entity. 

Chicagolooper

EESignature

0 Likes
Message 4 of 5

ativaderbrazil
Observer
Observer

Create a Lisp routine that iterates through selected objects. For each object, increment a counter and assign the value to the OBJECTID property using ADEATTACHDATA.

(defun C:AUTOINCID (/ ss obj cnt)
  (setq ss (ssget '((0 . "X"))))
  (setq cnt 1)
  (if ss
    (repeat (sslength ss)
      (setq obj (entget (ssname ss (setq cnt (1- cnt)))))
      (adeattachdata obj "OBJECTID" (itoa cnt))
      (entmod obj)
    )
  )
  (princ "ObjectID values assigned.")
)
0 Likes
Message 5 of 5

braudpat
Mentor
Mentor

Hello @randycarrion235LPXM @ativaderbrazil @ChicagoLooper @АлексЮстасу 

 

I have a very basic Lisp routine "OD_Incr_Numeric" to increment numeric OD with 4 questions :

- Table OD Name ?

- Field (numeric) OD Name ?

- Start Value ?

- Step Value ?

 

ATTENTION: no error management, so you must GIVE the right values for the Table & Field OD Names !

And select object with the right OD Table AND which are not on a locked layer !

 

SORRY it is a French version ... Do you need an US/English version ? 

 

Bye, Pat

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature