CAD Handle Export

CAD Handle Export

Anonymous
Not applicable
6,387 Views
28 Replies
Message 1 of 29

CAD Handle Export

Anonymous
Not applicable

Hi

 

I'm currently looking for a way of exporting CAD Handles from a drawing or more preferably a set of drawings in a directory. Ideally, the X,Y coordinates Rotation and Block Names also. 

 

The Data Extraction tool doesn't include the CAD Handles unfortunately and all of the LISP sites i've visited dont perform this either. 

 

I have no idea how to write LISP but does someone have a tool or a way of extracting this information? 

 

Much appreciated in advance 🙂 

 

Thanks

 

 

0 Likes
Accepted solutions (1)
6,388 Views
28 Replies
Replies (28)
Message 2 of 29

pendean
Community Legend
Community Legend
What exactly are you calling CAD HANDLES please?
Message 3 of 29

imadHabash
Mentor
Mentor

Hi,

 

i suggest to follow and read this AKN article that it may help. >> Click <<

 

Regards,

Imad Habash

EESignature

0 Likes
Message 4 of 29

Anonymous
Not applicable

CAD Handles as in the following, as an excerpt from a LIST command where the Handle is 41430;

 

Space: Model space
Transparency: 0
Handle = 41430
Block Name: "Gondola 48x20x84"
at point, X=167'-2 1/2" Y=88'-4 1/2" Z= 0'-0"
X scale factor: 1.0
Y scale factor: 1.0
rotation angle: 90.0
Z scale factor: 1.0
Scale uniformly: No
Allow exploding: Yes

 

I don't know how the article will help me extract the CAD Handles from a drawing though. 

 

Does that help? 

0 Likes
Message 5 of 29

Anonymous
Not applicable

CAD Handles as in the following, as an excerpt from a LIST command where the Handle is 41430;

 

Space: Model space
Transparency: 0
Handle = 41430
Block Name: "Gondola 48x20x84"
at point, X=167'-2 1/2" Y=88'-4 1/2" Z= 0'-0"
X scale factor: 1.0
Y scale factor: 1.0
rotation angle: 90.0
Z scale factor: 1.0
Scale uniformly: No
Allow exploding: Yes

 

I don't know how the article will help me extract the CAD Handles from a drawing though. 

 

Does that help? 

0 Likes
Message 6 of 29

devitg
Advisor
Advisor

Please show us the sample DWG , and the extract format .

 

 

0 Likes
Message 7 of 29

Kent1Cooper
Consultant
Consultant

What I'd be interested to know is what you want to do  with the Handles you export.  From what I know about them, they would be utterly meaningless except inside the drawing file itself as object identifiers.  They're actually text strings representing hexadecimal [base-16] integers, so if you want to do anything involving, for example, comparative numerical values, you'd presumably have to convert them to actual base-10 numbers.

Kent Cooper, AIA
0 Likes
Message 8 of 29

devitg
Advisor
Advisor

Maybe he need to check a list , and pick handles to erase .

 

By any filter .

 

Maybe he want to dig on hexadecimal numbers. 

 

As ever posters ask HOW to do , and not WHAT do. 

 

 

 

 

0 Likes
Message 9 of 29

roland.r71
Collaborator
Collaborator

@Kent1Cooper wrote:

What I'd be interested to know is what you want to do  with the Handles you export.  From what I know about them, they would be utterly meaningless except inside the drawing file itself as object identifiers.  They're actually text strings representing hexadecimal [base-16] integers, so if you want to do anything involving, for example, comparative numerical values, you'd presumably have to convert them to actual base-10 numbers.



it's a constant entity identifier, as opposed to the session depending entity name.

 

so you can save it, with some more info you like (like attribute values, or entity properties)

close the drawing. Manipulate the file with notepad, or whatever, & read it back (in a new session).

 

I've used this for editing terminal lists for example.

 

it's actually the entity name which is meaningless outside the current session of the drawing.

0 Likes
Message 10 of 29

Anonymous
Not applicable

I need the Handle extract as a means to import data into SQL. We have converted client drawings that contain (at the SQL level) block instance attribution. This data is stored in the client database against the CAD Handle of each store drawing of the previous block library. 

 

We have converted their original block with a new block that contains a new CAD Handle. In order to re-insert the block attributes into a new database i need the CAD Handle of the new block to re-establish the relationship. 

 

Attached is an example of a drawing that we are using. I have removed EVERYTHING (because i am tied to an Non-disclosure agreement) apart from a few examples to give an indication of what it is I'm trying to do. 

 

For reference, old block is contained on Old_Fixture layer and new Block is contained on FP_Fixture

 

Hopefully this will answer your questions about what i'm trying to accomplish. I would need an extract to include Old Block Name, Old CAD Handle, Old X&Y coord, Old Block Rotation, New Block Name, New CAD Handle, New X&Y coord & New Block Rotation, 

 

Is this possible fellas? 

 

 

0 Likes
Message 11 of 29

DannyNL
Advisor
Advisor

Extracting the data is the easy part.

The question is how do you relate the old to the new block (block names combined with insertion point?) and how do you want the information exported (.csv would be the easiest).

 

The example below will just extract the information for all blocks in your current layout and print a list with the info in the text screen of AutoCAD.

 

(defun c:BlockExtract (/ BE_ActiveSpace BE_DataList)
   (setq BE_ActiveSpace (vla-get-Block (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object)))))
   (vlax-for BE_Object BE_ActiveSpace
      (if
         (= (vla-get-ObjectName BE_Object) "AcDbBlockReference")
         (setq BE_DataList
            (append
               BE_DataList
               (list
                  (list
                     (vla-get-EffectiveName BE_Object)
                     (vla-get-Handle BE_Object)
                     (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint BE_Object)))
                     (* (vla-get-Rotation BE_Object) (/ 180 pi))                     
                  )
               )
            )
         )
      )
   )
   (textscr)
   (if
      BE_DataList
      (foreach BE_Item BE_DataList
         (princ "\n")
         (princ (vl-prin1-to-string BE_Item))
      )
   )
   (vlax-release-object BE_ActiveSpace)
   (princ)
)
0 Likes
Message 12 of 29

Anonymous
Not applicable

Hey Danny

 

That's brilliant and exactly what i'm looking for. 

 

You're right, i'm going to establish the relationship using the Insertion point - i can't use the block name because the Old Block Name and New Block Name differ. 

 

Can this tool generated the list into to CSV and can it look at a directory instead of single drawing. The second part of that is not a problem if not, there are only 120 drawings to run this against. 

 

Thanks again

0 Likes
Message 13 of 29

roland.r71
Collaborator
Collaborator

For the second part, you need something to create a script.

As you can not run a lisp on multiple drawings like that.

Basically it only works inside the current drawing (where the lisp was loaded)

 

So, you need a batch script to open each drawing, load the lisp & execute it. (appending the info to your *.csv)

 

There are some programs out there that can do it for you, or you need another lisp to select the drawings and create the script.

 

I've made some of those around here already. If i find the time i'll have a look...

0 Likes
Message 14 of 29

Anonymous
Not applicable

Thanks Roland. 

 

How do i finish the lisp file previously created by exporting to csv? 

0 Likes
Message 15 of 29

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

Thanks Roland. 

 

How do i finish the lisp file previously created by exporting to csv? 


I'm not sure i understand your question... (you don't create lisp files by exporting to csv)

 

What you need is: A lisp file containing the extraction function. Like DannyNL's (but modified to export the info to a .csv file)

 

& a program/lisp that allows you to select multiple dwg's & a lisp file (the above) to run on all, to generate a script file (autocad batch)

 

The lisp should of course be written in such a way that it will create a new .csv file at the start and append each drawings info to that .csv.

 

So:

1 lisp (*.lsp) to read 1 drawing.

1 lisp (or 3rd party program) to create a script (*.scr), to execute that lisp on multiple drawings.

 

the end result is (or: can be) a *.csv file containing all info.

 

0 Likes
Message 16 of 29

Anonymous
Not applicable

Hi Roland

 

I understand you can't create lisp files by exporting to csv 🙂 

 

my immediate concern with this is to export the data from the drawing to a csv. I was hoping that either yourself or Danny could add the ability to export the data to csv into the lisp code that Danny has already posted here. 

 

The ability to perform this on multiple drawings is secondary (to yours and and Danny's point i can use Autoscript which i have installed)

0 Likes
Message 17 of 29

roland.r71
Collaborator
Collaborator

Aah, now i see what you ment 🙂

 

Yes, that's possible. Although i haven't yet, since the code is @DannyNL's and i believe he's very capable to do it himself. (which would be best, i think)

...but i could do it too.

Message 18 of 29

DannyNL
Advisor
Advisor

Good to hear it can help you out. I was caught up in some work, but here is the modified code.

 

No formatting whatsoever, just a comma delimited output of the information as extracted out of the blocks. Information will be written to the file BlockExtract.csv in the same folder as the drawing.

If you have run the routine (manually or through script) on multiple drawings in the same folder, the information will be added to the existing CSV. As the CSV will be a possible collection of information from multiple different drawings (and you might want to merge multiple CSV from different folders) I've added the full filename of the drawing to the output as well.

 

(defun c:BlockExtract (/ BE_ActiveSpace BE_DataList BE_CSVFileID BE_ActiveDoc BE_WriteLine)
   (setq BE_ActiveSpace (vla-get-Block (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object)))))
   (vlax-for BE_Object BE_ActiveSpace
      (if
         (= (vla-get-ObjectName BE_Object) "AcDbBlockReference")
         (setq BE_DataList
            (append
               BE_DataList
               (list
                  (list
                     (vla-get-EffectiveName BE_Object)
                     (vla-get-Handle BE_Object)
                     (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint BE_Object)))
                     (* (vla-get-Rotation BE_Object) (/ 180 pi))                     
                  )
               )
            )
         )
      )
   )
   (if
      BE_DataList
      (progn
         (setq BE_CSVFileID (open (strcat (vla-get-Path (setq BE_ActiveDoc (vla-get-ActiveDocument (vlax-get-acad-object)))) "\\BlockExtract.csv") "a"))
         (foreach BE_Item BE_DataList
            (setq BE_WriteLine "")
            (foreach BE_SubItem BE_Item
               (setq BE_WriteLine (strcat BE_WriteLine (vl-princ-to-string BE_SubItem) ","))
            )
            (setq BE_WriteLine (strcat BE_WriteLine (vla-get-FullName BE_ActiveDoc)))
            (write-line BE_WriteLine BE_CSVFileID)
         )
         (close BE_CSVFileID)
      )
   )
   (mapcar 'vlax-release-object (list BE_ActiveSpace BE_ActiveDoc))
   (princ)
)
0 Likes
Message 19 of 29

DannyNL
Advisor
Advisor

A small modification to my code to answer your previous unanswered question. Yes, you can process all drawings at once.

Some preparation on your side; the easiest way to process is to make sure that (a copy of) your drawings are in one folder.

 

I've modified my code to support ODBX as this will be superior in processing speed in comparison to scripting over multiple drawings. One significant difference is it will now only extract blocks from ModelSpace (as in your example drawing) and not the last active layout from the last SAVE.

 

For this routine to work you will need the ObjectDBX Wrapper from Lee Mac from his website. Just download the LSP file and make sure you are loading it in a empty drawing or any other drawing that is not part of the batch to be processed.

 

http://www.lee-mac.com/odbxbase.html

 

Next load my modified code below and run the command RUNBLKEXTRACT.

Now select the folder with your drawings, click OK, get a cup of coffee (quickly as it will be finished before you know it) and check out the CSV in the same folder as your drawings.

 

(defun BlockExtract (BE_ODBX / BE_ActiveSpace BE_DataList BE_CSVFileID BE_ActiveDoc BE_WriteLine)
   (setq BE_ActiveSpace (vla-get-ModelSpace BE_ODBX))
   (vlax-for BE_Object BE_ActiveSpace
      (if
         (= (vla-get-ObjectName BE_Object) "AcDbBlockReference")
         (setq BE_DataList
            (append
               BE_DataList
               (list
                  (list
                     (vla-get-EffectiveName BE_Object)
                     (vla-get-Handle BE_Object)
                     (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint BE_Object)))
                     (* (vla-get-Rotation BE_Object) (/ 180 pi))                     
                  )
               )
            )
         )
      )
   )
   (if
      BE_DataList
      (progn
         (setq BE_CSVFileID (open (strcat (vl-filename-directory (vla-get-Name BE_ODBX)) "\\BlockExtract.csv") "a"))
         (foreach BE_Item BE_DataList
            (setq BE_WriteLine "")
            (foreach BE_SubItem BE_Item
               (setq BE_WriteLine (strcat BE_WriteLine (vl-princ-to-string BE_SubItem) ","))
            )
            (setq BE_WriteLine (strcat BE_WriteLine (vla-get-Name BE_ODBX)))
            (write-line BE_WriteLine BE_CSVFileID)
         )
         (close BE_CSVFileID)
      )
   )
   (mapcar 'vlax-release-object (list BE_ActiveSpace))
   (princ)
)

(defun c:RunBlkExtract ( / )
    (LM:ODBX
      'BlockExtract
       nil
       nil
    )
)

 

0 Likes
Message 20 of 29

Anonymous
Not applicable

hi Danny

 

I took your previous lisp code and used the AutoScript tool i have on my machine to execute on multiple drawings. 

 

It works perfectly thank you. 

 

I do have a question on it. Some blocks on some drawings that were returned occur more than once in the output. Do you know why this would be? It's not a problem, i can filter them out, but i am curious why that would be. 

 

Thanks

0 Likes