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

Batch insert reference(Xref)

28 REPLIES 28
SOLVED
Reply
Message 1 of 29
Anonymous
4026 Views, 28 Replies

Batch insert reference(Xref)

Batch  insert reference(Xref)

 

Select a folder and insert all DWG file to drawing from the folder. 

 I think need a Dcl file to enter the Rows and columns, Line spacing and the column spacing.

 

Drawing frame and title bar is Attribute block.

 

Drawing number: xxx-xxx-001 ,xxx-xxx-002 ......

Can use Drawing number from left to right, from top to bottom of the order arrange?

Tags (2)
28 REPLIES 28
Message 2 of 29
Anonymous
in reply to: Anonymous

No one to help me?Woman Sad

Message 3 of 29
Anonymous
in reply to: Anonymous

xref command can't select multiple DWGs.

Message 4 of 29
hmsilva
in reply to: Anonymous


@Anonymous wrote:

Batch  insert reference(Xref)

 

Select a folder and insert all DWG file to drawing from the folder. 

 I think need a Dcl file to enter the Rows and columns, Line spacing and the column spacing.

 

Drawing frame and title bar is Attribute block.

 

Drawing number: xxx-xxx-001 ,xxx-xxx-002 ......

Can use Drawing number from left to right, from top to bottom of the order arrange?


Hi emk2012,

what kind of dwg's are you trying to attach as xref.

Are survey dwg's, or another kind of dwg's, are all referenced to the same origin or not...

If possible, attach some sample dwg's.

 

Henrique

EESignature

Message 5 of 29
Anonymous
in reply to: hmsilva

(defun c:dw ()
(onxline )
(prin1)
)

(defun onxline ()
(setq *error* pt_err)
(setq sxkkey 0)
(initget 1 "Aboom")
(setq p0(getpoint "\npick a point:"))
(while (= p0 "Aboom")
(setq sxkkey 1)

(setq p0(getpoint "\npick a point:"))
)
(setq dist(getreal "\nSpacing:<0>"))
(if (= dist nil)(setq dist 0))

(if (= sxkkey 1)
(progn
(setq ss (ssget  '((0 . "INSERT")(2 . "图框 GB-hufei"))  ))  ;;;;;;;;;Here is the drawing frame block name(2 . "图框 GB-hufei*")
(setq ss (sort-se (sort-se ss 10 0 50 nil) 10 1 50 t )))
(progn
(setq ss(ssget '( (0 . "insert") )) )
(setq ss (sort-se ss 2 0 50 nil))
)
)

(setq os(getvar 'osmode))
(setvar 'cmdecho 0)
(setvar 'osmode 0)
(setq i 0)
(repeat   (sslength ss)
(setq entname(ssname ss i))
(setq qq (cornerp entname))
(setq p1(car qq) p2(cadr qq))
(if (=  sxkkey 1)
(PROGN
(setq ssall(ssget "w" p1 p2   ))
(command "_.move" ssall "" p1 p0))
(command "_.move" entname "" p1 p0)
)
(setq qq(cornerp entname))
(setq p1(car qq) p2(cadr qq))
(setq p0(cons (car p2) (cdr p1)))
(setq p0(polar p0 0 dist))

(setq i(1+ i))
)
(setvar 'osmode os)
(setvar 'cmdecho 1)
(prin1)
)



(defun pt_err()
(setvar 'osmode os)
(setvar 'cmdecho 1)
(prin1))

(DEFUN cornerp(entname)                 
 (vla-getboundingbox (vlax-ename->vla-object entname) 'entpl 'entpr)
 (setq ptlist (mapcar 'vlax-safearray->list (list entpl entpr)))
 (mapcar '(lambda (x) (trans x 0 1)) ptlist)
)

(vl-load-com)
(defun SORT-SE (SE DXF INT FUZZ K / ENT INDEX LST NEWLST NEWSE TMP)

  (setq LST '() INDEX 0)
  (repeat (sslength SE)
    (setq ENT (entget (ssname SE INDEX))
 TMP (cdr (assoc DXF ENT)) )

    (if (and INT (= (type INT) 'INT) (= (type TMP) 'list)(< INT (length TMP)) )
        (setq TMP (nth INT TMP)))

    (setq LST (cons (list TMP (cdr (assoc 5 ENT))) LST))
    (setq INDEX (1+ INDEX)))

  (if (and FUZZ
  (or (= (type FUZZ) 'INT)
      (= (type FUZZ) 'REAL))
  (or (= (type TMP) 'INT) (= (type TMP) 'REAL)))
    (setq NEWLST
(vl-sort LST (function (lambda (E1 E2) (< (+ (car E1) FUZZ) (car E2)))
)))
    (setq NEWLST
(vl-sort LST (function (lambda (E1 E2) (< (car E1) (car E2))))
)))         
  (if K (setq NEWLST (reverse NEWLST)))
  (setq NEWSE (ssadd))
  (foreach TMP NEWLST
    (setq NEWSE (ssadd (handent (cadr TMP)) NEWSE))
)  
)
(prin1)

 

Drawing number: xxx-xxx-001 ,xxx-xxx-002 ......

My wish is  sort with Drawing number from left to right, from top to bottom.

 

 

Message 6 of 29
Anonymous
in reply to: Anonymous

Hi hmsilva , whare are you ? 

 

Message 7 of 29
hmsilva
in reply to: Anonymous


@Anonymous wrote:

Hi hmsilva , whare are you ? 

 


Hi emk2012,

 

I'm working!

 

Here at the forums, we all try to get help and to help others in our spare time.
I have a deadline to meet, so at the moment, I don't have much free time.

 

If no one else step in to help you, I'll see what can I do when I have more free time...

But in order to get help, firstly you'll have to help us explaining what your goal, in the most objective possible way.

 

At post #1 you had written:

"Batch  insert reference(Xref)
Select a folder and insert all DWG file to drawing from the folder.
I think need a Dcl file to enter the Rows and columns, Line spacing and the column spacing.
Drawing frame and title bar is Attribute block.
Drawing number: xxx-xxx-001 ,xxx-xxx-002 ......
Can use Drawing number from left to right, from top to bottom of the order arrange?"

 

But at post #10 you have attached a code just to move INSERTS, and ask for

 

"My wish is  sort with Drawing number from left to right, from top to bottom."

 

Don't you want to attach all dwgs from one foldes as xref's any more?

 

Henrique

EESignature

Message 8 of 29
Anonymous
in reply to: hmsilva

I'm so sorry! I don't know you are busy!

 

Here is the batch insert Xref 

 


(defun c:BatchXref () (setvar "tilemode" 1) (princ "\n\nPick any drawing in the set.") (setq pickfile (getfiled "Pick any drawing in the set" "g:/" "dwg" 2)) ;;; type in your preferred path... ; ;extract just the path (setq filelen (strlen pickfile)) (setq letter "") (while (/= letter "\\") (setq letter (substr pickfile filelen 1)) (setq filelen (- filelen 1)) ) (setq filelen (+ filelen 1)) (setq path (substr pickfile 1 filelen)) ; ;list all floor plan drawings in that directory (vl-load-com) (setq filelist (vl-directory-files path "*.dwg")) ; ;xref all floor plans into current drawing (setq counter 0) (setvar "filedia" 0) (repeat (length filelist) (setq currentfile (strcat path (nth counter filelist))) (command "-xref" "a" currentfile "0,0,0" "1" "" "0") (setq counter (+ counter 1)) ) (setvar "filedia" 1) )

 

Message 9 of 29
hmsilva
in reply to: Anonymous

Hi emk2012,

the code structure I thought to achieve your goal,
"selecting a folder, attach all dwg's as xref's, from the left to the right and from the top to the bottom using the number in the block inside each dwg, and entering the number of rows (the number of columns should be calculated from the number of drawings in the selected directory divided by the entered number of rows) and the vertical/horizontal spacing between dwg's"
is:

- using ObjectDBX, open all dwg's in the selected folder, make a sorted list with the number/dwgname.
- attach all xref's using the previous list order.

 

But I'm having some problems (linguistic/fonts) with your dwgs names and using ObjectDBX...
For testing purpose, try the attached code and see if it gives an error or not.
At (= (vla-get-name blk) "??? GB-hufei") change to the correct block name, run the code, press F2 and copy/paste the result here.

 

Henrique

EESignature

Message 10 of 29
Anonymous
in reply to: hmsilva

 @hmsilva.

 

Thanks very much! hmsilva. 

 

I have changed the block name in your routine. 

appload and run command "test" 

 

selecting a folder  , done.

nothing is to do.

 

Command: test
nil
Command:

 

Message 11 of 29
hmsilva
in reply to: Anonymous

I did not expect that result!
When I test with your dwg's, this is what I get
Command: TEST
; error: Automation Error. Description was not provided.
Command:
after renaming your dwg's, this is what I get
Command:  TEST
((SS-04-011-027 . C:\a-ext\A-Ext\USERS\emk2012\01\ghi456.idw.dwg) (SS-04-011-105 . C:\a-ext\A-Ext\USERS\emk2012\01\jkl789.idw.dwg) (SS-04-011-146 . C:\a-ext\A-Ext\USERS\emk2012\01\mno567.idw.dwg) (SS-04-011-166 . C:\a-ext\A-Ext\USERS\emk2012\01\abc100.idw.dwg) (SS-04-011-283 . C:\a-ext\A-Ext\USERS\emk2012\01\def2091.idw.dwg))
Command:

The nil answer, should means that the code has failed to find the block and/or didn't find the attribut value to make the list.
Try the code, without replacing the block name.

 

Henrique

 

EESignature

Message 12 of 29
Anonymous
in reply to: hmsilva

without replacing the block name,  The result is the same.

Message 13 of 29
hmsilva
in reply to: Anonymous

Try copy/paste the following code lines, one at a time at the command line, select the block and the text, and post the result
(vl-load-com);; if needed
(vla-get-name (vlax-ename->vla-object (car (entsel "\nSelect the Attribut Block : "))))
(vla-get-textstring (vlax-ename->vla-object (car (entsel "\nSelect the Attribut Text, ex. <SS-04-011-166>: "))))

Henrique

EESignature

Message 14 of 29
Anonymous
in reply to: hmsilva

Select the Attribut Block : "图框 GB-hufei"

 

Select the Attribut Text, ex. <SS-04-011-166>: ; error: ActiveX Server returned
the error: unknown name: TextString

 

 

Message 15 of 29
hmsilva
in reply to: Anonymous


emk2012 wrote:

 

Select the Attribut Text, ex. <SS-04-011-166>: ; error: ActiveX Server returned
the error: unknown name: TextString

 

 



Sorry, my bad....

try

(vla-get-textstring (vlax-ename->vla-object (car (nentsel "\nSelect the Attribut Text, ex. <SS-04-011-166>: "))))

EESignature

Message 16 of 29
Anonymous
in reply to: hmsilva

Select the Attribut Text, ex. <SS-04-011-166>: "\\W0.7500;SS-04-011-085"

Message 17 of 29
hmsilva
in reply to: Anonymous


@Anonymous wrote:

Select the Attribut Block : "图框 GB-hufei"

 



The block name I get have three characters "??? GB-hufei" and the block name you have posted only have two characters "?? GB-hufei", are you selecting the correct block, and changed the code to the correct block name???

 

Henrique

EESignature

Message 18 of 29
Anonymous
in reply to: hmsilva

   (= (vla-get-name blk) "??? GB-hufei");;<<< Change the block name to the correct one

 

I change "??? GB-hufei" to correct block name .

Message 19 of 29
Anonymous
in reply to: hmsilva

I test it in AutoCAD 2007 and AutoCAD 2010, is the same.

 

Command: TEST
nil
Command:

Message 20 of 29
hmsilva
in reply to: Anonymous


@Anonymous wrote:

   (= (vla-get-name blk) "??? GB-hufei");;<<< Change the block name to the correct one

 

I change "??? GB-hufei" to correct block name .


BlockName.png

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost