Page setup import (if not)

Page setup import (if not)

msarqui
Collaborator Collaborator
1,260 Views
6 Replies
Message 1 of 7

Page setup import (if not)

msarqui
Collaborator
Collaborator

Hi guys,

 

I made this very simple routine to import the page setup from my template.

 

(defun c:IPS ()
(command "._-PSETUPIN" "C:/Users/mds/Documents/plot_configurations.dwg" "*")
);defun

 

But, if I already have the page setup names in my drawing, AutoCAD will ask me to redefine one by one.

Is that a way to verify if the page setup exists, and if doesn't, do the import command?

 

Thanks

0 Likes
Accepted solutions (1)
1,261 Views
6 Replies
Replies (6)
Message 2 of 7

msarqui
Collaborator
Collaborator

Well, so far I got this:

 

(defun c:IPS (/ exp)

(setq exp (getvar "EXPERT"))
(setvar "EXPERT" 2)
(command "._-PSETUPIN" "C:/Users/mds/Documents/plot_configurations.dwg" "*")
(setvar "expert" exp)

);defun

 

The EXPERT variable avoid the redefine question. It is not what I would like, but it is a start.

0 Likes
Message 3 of 7

hmsilva
Mentor
Mentor

Hi Marcelo,

 

to copy page setups, with different names from those in current document, perhaps something like this

 

;; (psetup_in "C:\\Users\\mds\\Documents\\plot_configurations.dwg")
(vl-load-com)
(defun psetup_in (target / *error* dbx dbx_pltcfgs id lst name new setup pltcfgs)

  (defun *error* (msg)
    (if dbx
      (vlax-release-object dbx)
    )
    (cond
      ((not msg))
      ((wcmatch (strcase msg) "*QUIT*,*CANCEL*"))
      (T (princ (strcat "\nError: " msg)))
    )
    (princ)
  )

  (if
    (findfile target)
     (progn
       (or acdoc (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))))
       (setq pltcfgs (vla-get-plotconfigurations acdoc))
       (if (> (vla-get-count pltcfgs) 0)
         (vlax-for pltcfg pltcfgs
           (setq lst (cons (vla-get-name pltcfg) lst))
         )
       )
       (setq Id (strcat "objectdbx.AxDbDocument." (substr (getvar "acadver") 1 2)))
       (setq dbx (vlax-create-object Id))
       (vla-open dbx target)
       (setq dbx_pltcfgs (vla-get-plotconfigurations dbx))
       (if (> (vla-get-count dbx_pltcfgs) 0)
         (vlax-for dbx_pltcfg dbx_pltcfgs
           (if (or (and lst
                        (not (vl-position (setq name (vla-get-name dbx_pltcfg)) lst))
                   )
                   (null lst)
               )
             (progn
               (setq new_setup (vla-add pltcfgs name :vlax-false))
               (vla-CopyFrom new_setup dbx_pltcfg)
             )
           )
         )
       )
     )
  )
  (*error* nil)
  (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 4 of 7

msarqui
Collaborator
Collaborator

Hi Henrique,

 

The reason I am asking this is because I am using the WBLOCK to clean some drawings. This process works realy good but it has one issue: the page setup disappears and to print or to plot without this is to hard. So, I am trying to import it from another drawing with a lisp routine because I will do this cleaning process many times from now. 

That said, the routine will be put in my acaddoc.lsp on the server. So, when someone open a drawing, it will check if the drawing already has the same page setup from my template, and if idoesn't, the routine will import it. I am using AutoCAD2012.

 

I did some tests with this:

(defun c:test ()

(psetup_in "C:\\Users\\mds\\Documents\\plot_configurations.dwg")

)

 

If the drawing already has the same page setup, nothing happens (this is perfect)

If the drawing has at least one page setup, the others will be imported (this is perfect)

But, if the drawing has none page setup, I have this error :

Error: ActiveX Server returned an error: Parameter not optional

Maybe here, you could create one page setup named "Setup1", do the import, and at the end erase this "Setup1" page setup...

 

 

I also did some tests with this:

(psetup_in "C:\\Users\\mds\\Documents\\plot_configurations.dwg")

 

In all the cases (with or without page setups), I have this error:

; error: no function definition: PSETUP_IN

 

Thanks!

0 Likes
Message 5 of 7

hmsilva
Mentor
Mentor
Accepted solution

Marcelo,

 

try this revised code

 

(vl-load-com)
(defun psetup_in_if_not (target / *error* dbx dbx_pltcfgs id lst name new_setup pltcfgs)

  (defun *error* (msg)
    (if dbx
      (vlax-release-object dbx)
    )
    (cond
      ((not msg))
      ((wcmatch (strcase msg) "*QUIT*,*CANCEL*"))
      (T (princ (strcat "\nError: " msg)))
    )
    (princ)
  )

  (if
    (findfile target)
     (progn
       (or acdoc (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))))
       (setq pltcfgs (vla-get-plotconfigurations acdoc))
       (if (> (vla-get-count pltcfgs) 0)
         (vlax-for pltcfg pltcfgs
           (setq lst (cons (vla-get-name pltcfg) lst))
         )
       )
       (setq Id (strcat "objectdbx.AxDbDocument." (substr (getvar "acadver") 1 2)))
       (setq dbx (vlax-create-object Id))
       (vla-open dbx target)
       (setq dbx_pltcfgs (vla-get-plotconfigurations dbx))
       (if (> (vla-get-count dbx_pltcfgs) 0)
         (vlax-for dbx_pltcfg dbx_pltcfgs
           (setq name (vla-get-name dbx_pltcfg))
           (if (or (and lst
                        (not (vl-position name lst))
                   )
                   (null lst)
               )
             (progn
               (setq new_setup (vla-add pltcfgs name :vlax-false))
               (vla-CopyFrom new_setup dbx_pltcfg)
             )
           )
         )
       )
     )
  )
  (*error* nil)
  (princ)
)


(defun c:demo ()
  (psetup_in_if_not "C:\\Users\\mds\\Documents\\plot_configurations.dwg")
  (princ)
)

 

I can't reproduce this error...

 

'In all the cases (with or without page setups), I have this error:

; error: no function definition: PSETUP_IN''

 

Hope this helps,
Henrique

 

 

EESignature

Message 6 of 7

msarqui
Collaborator
Collaborator
What else can I say?
Many thanks Henrique. It is perfect now!
0 Likes
Message 7 of 7

hmsilva
Mentor
Mentor

@msarqui wrote:
What else can I say?
Many thanks Henrique. It is perfect now!

You're welcome, Marcelo!
Glad I could help

Henrique

EESignature

0 Likes