Help in lisp for bind dwg

Help in lisp for bind dwg

cool.stuff
Collaborator Collaborator
291 Views
5 Replies
Message 1 of 6

Help in lisp for bind dwg

cool.stuff
Collaborator
Collaborator

Hello 🙂

I am trying to code a lisp to bind xrefs of several dwgs.

 

My code is this:

 

(defun c:XBD ()
  (setvar "FILEDIA" 0)
  (setvar "SDI" 1)
  (setq dwgl (LM:directoryfiles "C:\\Users\\usr\\Desktop\\New folder" "*.dwg" nil))
  (foreach dwg dwgl
    (c:PD dwg)
  )
  ;(setvar "FILEDIA" 1)
  ;(setvar "SDI" 0)
  (princ)
)

(defun LM:directoryfiles ( dir typ sub )
  (setq dir (vl-string-right-trim "\\" (vl-string-translate "/" "\\" dir)))
  (append
    (mapcar '(lambda ( x ) (strcat dir "\\" x))
            (vl-directory-files dir typ 1))
    (if sub
      (apply 'append
        (mapcar
          '(lambda ( x )
             (if (not (wcmatch x "`.,`.`."))
               (LM:directoryfiles (strcat dir "\\" x) typ sub)))
          (vl-directory-files dir nil -1))))))

(defun c:PD (dwgp)
  (command "_.OPEN" dwgp)
  (foreach ln (layoutlist)
    (c:PLN ln)
  )
  ;(setvar "FILEDIA" 1)
  ;(setvar "SDI" 0)
  (c:DP dwgpath)
  (command "_.close" "y")
  (c:CP)
)

(defun c:PLN (LN)
  (cond
	((or (= LN "Layout2") (= LN "Layout1"))
	 (command "-LAYOUT" "_d" LN)
	 )
    (T
    )
  )
)

(defun c:CP ( / )
  (setvar "PUBLISHALLSHEETS" 0)
  
  (setvar "FILEDIA" 0)
  (setvar "CMDDIA" 0)
  
  (command "_.PUBLISH")
  
  (setvar "FILEDIA" 1)
  (setvar "CMDDIA" 1)  
)

(defun c:DP (dwgpath)
	(command "_purge")
    (command "_.QSAVE")
    (command "_.CLOSE")
)

 

My current issues:

- I do know how to delete unreferenced or missing xref's for each drawing;

- I cannot make publish command work (using the current settings);

- I cannot make it work for all files. Once it opens the first file. it stops.

 

Also it only works on a blank project without changes...

 

Can someone help me please?

Many thanks 🙂

0 Likes
292 Views
5 Replies
Replies (5)
Message 2 of 6

Moshe-A
Mentor
Mentor

@cool.stuff  hi,

 

I am trying to code a lisp to bind xrefs of several dwgs

can not see any binding xrefs in your code?

 

My current issues:

- I do know how to delete unreferenced or missing xref's for each drawing;

you mean manually?

 

- I cannot make publish command work (using the current settings);

- I cannot make it work for all files. Once it opens the first file. it stops.

AutoLISP exist/works in an open drawing/editing session, as soon as you close drawing, there is no AutoLISP (your lisp program break)

 

to run a lisp command on a list of drawings you need to create a script file (.scr) to be run from outside AutoCAD or better use

 >> ScriptPro 2 <<  open each dwg run some lisp commands (like bind xrefs + plot to pdf) save and close (publish is more

designed to work manually and not be called from lisp).

 

Moshe

 

 

 

0 Likes
Message 3 of 6

cool.stuff
Collaborator
Collaborator

@Moshe-Ahello,

 

thanks for you answer.

sorry, I pasted an older attempt of my code.

And I have a typo in my post:

 

"(command "-xref" "b" "*")"

 

and I do not know how to bind all xrefs, deleting the unreferenced and missing ones.

 

Also, I do not know how to use the publish command in a lisp, using the current settings.

 

Thanks again 🙂

0 Likes
Message 4 of 6

Moshe-A
Mentor
Mentor

@cool.stuff ,

 

Why do you want to bind all xrefs? share your reasons and how binding xrefs is related to plotting?

i think you should separate these tasks cause in each of these task there are potential of errors

that will break your batch. 

 

Moshe

 

0 Likes
Message 5 of 6

cool.stuff
Collaborator
Collaborator

@Moshe-Athanks for your reply.

 

Ok, I will create 2 scripts for these tasks.

I have manage to create a script as you recommended.

Binding all xrefs is a normal need when publishing to dwg files (at least where I work).

Then, I need to publish all drawings. I have configured publish options but I dont know how to use this command to consider each layout current settings in a script. I need to publish to PDF, DWG and DWF.

 

Could you give me an example how to achieve this please?

Thanks

0 Likes
Message 6 of 6

Moshe-A
Mentor
Mentor

@cool.stuff ,

 

Sorry but i do not understand this:-

say i have a drawing hosting some xrefs and i publish it pdf

then i have the same drawing all xrefs are bind and publish it pdf

do i get a different printed pdfs?!

 

The standard PUBLISH is so strong and has many options for printing a list of drawings from model space and layouts,

it is automation by it self and i do not see any room to write a lisp to do better job.

 

Moshe

0 Likes