Jump to content

Gather information in one drawing and create the table in a seperate drawing


mwohlford

Recommended Posts

I wrote a lisp program that creates an equipment list from part numbers in selected blocks and a csv file with information about those part numbers.  It allows the user to then select a layout followed by an insertion point, then creates the table a populates it with the list.  On a small project were 4 or 5 sheets are all that is needed the sheets are in the same drawing file and this works great.  However, on larger projects the sheet that the equipment list needs to go on is not in the same drawing file.  Is there a way to select a layout in another file for the table to be created and inserted on?  I know I could save the list to a global variable, open the drawing with the sheet to insert on and create the table from there.  I would like to not have to ask the user to go through the extra steps.  Is it possible to maybe use getfiled to open a drawing to the specified sheet then create the table? Any guidance would be helpful whether with getfiled or some other method that I could work into my code.

Edited by mwohlford
Link to comment
Share on other sites

If you're familiar with using VLA methods, you can access another drawing yes. You use vla-get-ActiveDocument to get the vla-object of your active document... you can use the below (a snippet of the Steal Routine by Lee Mac) to get the vla object the document of another drawing.

 

(defun steal:getdocumentobject ( filename / acdocs dbdoc vers )
    (vlax-map-collection (vla-get-documents (vlax-get-acad-object))
        (function
            (lambda ( doc )
                (setq acdocs (cons (cons (strcase (vla-get-fullname doc)) doc) acdocs))
            )
        )
    )
    (cond
        (   (null (setq filename (findfile filename)))
            nil
        )
        (   (cdr (assoc (strcase filename) acdocs))
        )
        (   (null
                (vl-catch-all-error-p
                    (vl-catch-all-apply 'vla-open
                        (list
                            (setq dbdoc
                                (vla-getinterfaceobject (vlax-get-acad-object)
                                    (if (< (setq vers (atoi (getvar 'acadver))) 16)
                                        "ObjectDBX.AxDbDocument"
                                        (strcat "ObjectDBX.AxDbDocument." (itoa vers))
                                    )
                                )
                            )
                            filename
                        )
                    )
                )
            )
            dbdoc
        )
    )
)

 

So you can perform something like:

 

(foreach x '(your_list_of_dwg_paths)
    (setq dbdc (steal:getdocumentobject x))
    ;; and do your stuff here
    (vlax-release-object dbdc)
    )

 

Edited by Jonathan Handojo
  • Thanks 1
Link to comment
Share on other sites

Thank you for pointing me in the right direction.  If I understand the Lee Mac's function correctly, I will use the returned document object to create the table.  Since the drawing will not be visible I will need to provide a predetermined insertion point and layout for said table. I can then use vla-save before releasing the document.

 

I am having a hard time wrapping my head around how the cond statement is working with two null conditions.  Would you be willing to briefly explain to further my education?

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...