Jump to content

Named object dict retrieve from drawing and add to new emty drawing


Revnixcad
 Share

Recommended Posts

Posted (edited)

In our drawings we have some ESRI_ dicts we want to retrieve some dicts and there containing xrecords

 

(defun c:ESRI-INFO-GETTER (/ $mainDict $entMainDict $mainDictLength $mainDictIndex 
                          $entObjectdictEntry
                         ) 
  (prompt "\nArcgis dictionaries in current drawing: ")
  (setq $mainDict (namedobjdict))
  (setq $entMainDict (entget $mainDict))
  (setq $mainDictLength (length $entMainDict)) ; length of main dict entrys
  (setq $mainDictIndex 0) ; index of entry
  (while (< $mainDictIndex $mainDictLength) 
    (if 
      (and (= (car (nth $mainDictIndex $entMainDict)) 3) 
           (wcmatch (setq $dictName (cdr (nth $mainDictIndex $entMainDict))) 
                    "ESRI_*"
           ) ; filter on root tablenames beginning with ESRI
      )
      (progn 
      ;;;;;;;;;;;;;;;;;;;;;;;;;
      ; some recursive function
      ;;;;;;;;;;;;;;;;;;;;;;;;;
      )
    )
    (setq $mainDictIndex (+ $mainDictIndex 1)) ; increment index
  )
  (princ)
)

 

This is some basic loop to retrieve the specific dicts.

 

I'm working on this at the moment but want to pick some brains for a smart way to retrieve this data from drawing and insert this data in new empty one.

 

for the moment I am using this with AccoreConsole to select the drawing containings it's data and transfer to new drawings. (for know we have this working to add single entry's to this data tables)

Edited by Revnixcad
Link to comment
Share on other sites

  • 2 weeks later...
Posted (edited)

guys hopefully someone can enlight me because i'm really stuck at this moment.

I made this code so far with the following help file https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-D9E0A89C-2D81-4141-8B88-B9AC6EAABD62:

(vl-load-com)
; function is work in progress
(defun c:FIX-ESRI (/ $acadObject $document $acadTypeLibImport $objectDBXSource 
                   $objectDBXOutput $objCollection $eachObject $count $returnedObjects
                  ) 

  ;; Load the ObjectDBX library
  (if (= $acadTypeLibImport nil) 
    (progn 
      (vlax-import-type-library :tlb-filename "axdb24enu.tlb" :methods-prefix 
                                "acdbm-" :properties-prefix "acdbp-" :constants-prefix "acdbc-"
      ) ; stored .tlb file in same directory as lisp script
      (setq $acadTypeLibImport T)
    )
  )
  
  ;; Create a reference to the ObjectDBX object
  (setq $objectDBXSource (vlax-create-object "ObjectDBX.AxDbDocument.24")) 

  ;; Open an external source drawing file
  (acdbm-open 
    $objectDBXSource
    (findfile "<path to file>\\input-drawing.dwg") ; function need full path names list for dwgname
  )

  ;; Create a reference to the ObjectDBX object
  (setq $objectDBXOutput (vlax-create-object "ObjectDBX.AxDbDocument.24"))
  ;; Open an external output drawing file
  (acdbm-open 
    $objectDBXOutput
    (findfile "<path to file>\\output-drawing.dwg") ; function need full path names list for dwgname
  )

  ; Get Esri_* tables and info
  (setq $objCollection (list))
  (setq $index 0)
  (vlax-for $eachObject (vla-get-Dictionaries $objectDBXSource) 
    (if 
      (not 
        (vl-catch-all-error-p 
          (vl-catch-all-apply 'WTN:GET_DICT_NAME 
                              (list $eachObject)
          )
        )
      )
      (progn 
        (if (wcmatch (setq $dictName (WTN:GET_DICT_NAME $eachObject)) "ESRI_*") 
          (progn 
            (setq $objCollection (append $objCollection 
                                         (list $eachObject)
                                 )
            )
            (setq $index (1+ $index))
          )
        )
      )
    )
  )
  
  ; init safearray
  (setq $safeArray (vlax-make-safearray vlax-vbObject 
                                        (cons 0 (- (length $objCollection) 1))
                   )
  )
  
  ; make safarray
  (setq $count 0)
  (foreach $object $objCollection 
    (vlax-safearray-put-element $safeArray $count $object)
    (setq $count (1+ $count))
  )
  
  ; get modelspace of $objectDBXOutput
  (setq $modelSpaceOutput (vla-get-ModelSpace 
                            (vla-get-Database $objectDBXOutput)
                          )
  )

  ;copy objects
  (setq $returnedObjects (vla-CopyObjects $objectDBXSource 
                                          $safeArray
                                          $modelSpaceOutput
                         )
  )
  (vlax-release-object $objectDBXSource)
  (vlax-release-object $objectDBXOutput)
  (princ)
)

(defun WTN:GET_DICT_NAME ($dictionary) 
  (vlax-get-property $dictionary 'Name)
)

 

It gives an error on (vla-CopyObjects 

axdb24enu.tlb input-drawing.dwg output-drawing.dwg

Edited by Revnixcad
Link to comment
Share on other sites

i get the following error with vla-CopyObjects function

Automation Error. Illegal entity type

 

Code_iVjvZWp8zr.png

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
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.

 Share

×
×
  • Create New...