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

How to get a list of Page Setups from another, un-opened dwg

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
dmfrazier
729 Views, 11 Replies

How to get a list of Page Setups from another, un-opened dwg

I found a function on JTBWorld named listPageSetups, which appears to be meant for listing the pagesetups that exist in an "open" dwg file (as I can get it work for the current dwg).  So,

(1) Can this function be used to list page setups in another, un-opened dwg, and, if so, how?

(2) If the answer to (1) is No, is there a LISP way to get a list of page setups from another, un-opened dwg?

 

Thanks in advance.

11 REPLIES 11
Message 2 of 12
BlackBox_
in reply to: dmfrazier

If using LISP, you'll need to prompt the user to select a drawing, then open it using an ObjectDBX interface, and iterate the DBX Document's ACAD_PLOTSETTINGS Dictionary.

 

Let me know if you need help with the code.

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 3 of 12
dmfrazier
in reply to: BlackBox_

Thanks for the response.

 

I actually don't want to prompt the user, because the drawing is a known, fixed source.

 


@BlackBox_ wrote:

... open it using an ObjectDBX interface...


 

I'm not familiar with this concept.  If I know the drawing file to "open", is this something that can be done from within LISP so that it is transparent (invisible) to the user?

Message 4 of 12
Lee_Mac
in reply to: dmfrazier


@dmfrazier wrote:

I actually don't want to prompt the user, because the drawing is a known, fixed source.


@BlackBox_ wrote:

... open it using an ObjectDBX interface...


I'm not familiar with this concept.  If I know the drawing file to "open", is this something that can be done from within LISP so that it is transparent (invisible) to the user?


My Steal program will allow you to retrieve a list of Page Setups (amongst other items) from an unopened drawing, which may either be selected by the user or a fixed drawing set in the code.

 

As suggested by BlackBox, the program uses ObjectDBX to interface with the drawing database of the unopened drawing, without opening the drawing in the AutoCAD Editor window.

 

The program already offers five commands, however you can also call the program as an AutoLISP function with two optional arguments: the drawing filename from which to import items, and a list of items to be imported.

 

Examples of how the program may be called in this way are shown on the program page to which I have linked, under the heading 'Calling the Program as a Subfunction'.

 

If you need help using the program, just ask. Smiley Happy

 

I hope this helps!

Message 5 of 12
BlackBox_
in reply to: dmfrazier


@dmfrazier wrote:

Thanks for the response.

 

I actually don't want to prompt the user, because the drawing is a known, fixed source.

 


@BlackBox_ wrote:

... open it using an ObjectDBX interface...


 

I'm not familiar with this concept.  If I know the drawing file to "open", is this something that can be done from within LISP so that it is transparent (invisible) to the user?


No worries; removing the user prompt selection simplifies things a bit. :thumbsup:

 

Here's a working example of a sub-function which requires a single string argument (the Drawing name to be queried if within SFSP, or the full file path if not), which interfaces with ObjectDBX to open said Drawing and then iterates the appropriate Dictionary Collection Object, returning any/all resultant page setups:

 

(vl-load-com)

(defun bbox:ListPageSetups (dwg / *error* dbxDoc plotSettings)
  ;; Example:
  ;; (bbox:ListPageSetups "C:\\Users\\BlackBox\\DWG\\Foo.dwg")
  (defun *error* (msg)
    (if dbxDoc
      (vlax-release-object dbxDoc)
    )
    (cond ((not msg))                                                   ; Normal exit
          ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
          ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
    )
    (reverse plotSettings)
  )

  (if (and (setq dwg (findfile dwg))
           (setq dbxDoc (vla-getinterfaceobject
                          (vlax-get-acad-object)
                          (strcat "ObjectDBX.AxDbDocument."
                                  (substr (getvar 'acadver) 1 2)
                          )
                        )
           )
      )
    (progn
      (vl-catch-all-apply 'vla-open (list dbxDoc dwg))
      (vlax-for x (vla-item (vla-get-dictionaries dbxDoc)
                            "ACAD_PLOTSETTINGS"
                  )
        (setq plotSettings (cons (vla-get-name x) plotSettings))
      )
    )
  )
  (*error* nil)
)

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 6 of 12
BlackBox_
in reply to: BlackBox_

I've been trying to post that for +/- an hour, and kept getting some error message about a comma, and a flood (not kidding). *shrug*

 

 

 

Ahh... I forgot to suggest Steal; another great routine, Lee.

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 7 of 12
dmfrazier
in reply to: Lee_Mac

Just took a quick look, and it looks promising.  I will try it out as soon as I can get back to this.

Thanks very much.

Message 8 of 12
dmfrazier
in reply to: BlackBox_

I will try out your code as soon as I can get back to this.

Thanks very much.

Message 9 of 12
Lee_Mac
in reply to: BlackBox_


@BlackBox_ wrote:

I've been trying to post that for +/- an hour, and kept getting some error message about a comma, and a flood (not kidding). *shrug*


Same here - thought it was just me Smiley Frustrated

 


@BlackBox_ wrote:

Ahh... I forgot to suggest Steal; another great routine, Lee.


Cheers BB Smiley Happy

Message 10 of 12
BlackBox_
in reply to: Lee_Mac


@Lee_Mac wrote:

@BlackBox_ wrote:

I've been trying to post that for +/- an hour, and kept getting some error message about a comma, and a flood (not kidding). *shrug*


Same here - thought it was just me Smiley Frustrated

 


@BlackBox_ wrote:

Ahh... I forgot to suggest Steal; another great routine, Lee.


Cheers BB Smiley Happy


Not alone at all:

 

acad.error.comma.flood.png

 

Cheers dude. :beer:



"How we think determines what we do, and what we do determines what we get."

Message 11 of 12
dmfrazier
in reply to: dmfrazier

I like your "Steal" program (very similar to DesignCenter), but it turns out that it is actually simpler to use PSETUPIN for what I eventually chose to do.

My original thought was to have the user select one page setup from a (long) list of those available in a source dwg.  Instead, I decided it would be better to just go ahead and automatically import a small sub-set of the page setups based on the setup names.

Thanks, again.

Message 12 of 12
Lee_Mac
in reply to: dmfrazier


@dmfrazier wrote:

I like your "Steal" program (very similar to DesignCenter), but it turns out that it is actually simpler to use PSETUPIN for what I eventually chose to do.

My original thought was to have the user select one page setup from a (long) list of those available in a source dwg.  Instead, I decided it would be better to just go ahead and automatically import a small sub-set of the page setups based on the setup names.

Thanks, again.


 

You're welcome - I'm glad you found a solution to suit your needs Smiley Happy

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

Post to forums  

”Boost