Jump to content

How to look for a XREF file name and insert suitable block


Recommended Posts

Posted

Hi all,

 

There are five sheet sizes A, B , C, D, E. The xref file name is under \drawing\formats\A00.dwg (b00.dwg, C00.dwg etc...) for each sheet size. Currently I have a small block insertion utility which requires manual look-up (visually) of the sheet size and then choose the size of block insertion required and then fill up the attributes.

 

So, I made commands like BLKA, BLKB, BLKC, BLKD, BLKE separately. This is because I do not know how to search for the X-ref file name (not the x-ref name) and then use that as a variable to automatically insert using the block and attributes using just one command.

 

Any suggestions?

Posted

Can someone please provide me a way to resolve this?

Posted

Sounds like your not using layouts, once you create one with correct title block then just use copy to add another sheet, generally about 90% is the same per sheet, also look into sheet set manager.

 

If you only have 5 sheets sizes why not just have them all in your template just delete the blank layouts once you know wher your heading.

Posted

Thanks BIGAL for your suggestion.

 

We do have company templates but only few project requires inserting additional blocks and there are many people uses that sheet so I have no control over original templates to modify it. Thats the reason, I'm limited to insert the size specific block (which is not the title block) it the additional information pertaining to the drawing.

 

Once I insert the block, I fill up few attributes (which is thru lisp) so I was wondering, if AutoCAD can somehow look-up the sheet size thru xref properties and insert the block accordingly.

 

I can complete (or atleast try to build) my code but not sure how to look-up sheet size.

 

Any Idea on how ot look-up the sheet size?

 

 

(Defun C:blka  () (command "layout" "" "")
 (setvar "cmdecho" 0) 
 (setvar "attreq" 0)
 (Command "-INSERT" "XXXX/XXXX/BLOCK_A" "0,0" "" "" "")
 (princ "\nSelect Text file for attribute import:")
 (c:attin)
 (setvar "attreq" 1)
 (princ "\nAttributes copied & Updated")
  (command "eattedit" "L")
 (princ)
 )

  • 2 weeks later...
Posted

Can someone please provide me some guidance in this so that I can atleast try something on this?

 

Thanks

Posted

Here is a snap of the property manager where it lists down xref path.

New Picture.jpg

Posted

Not sure what you're after shailujp, If the files you are after is within a folder listed in your SFSP [support File Search Path] then you wont have any problems inserting the required block, just make sure when supplying the filename as argument for command insert to include findfile i.e. (findfile "d00.dwg")

 

..not sure how to look-up sheet size...

 

That i dont understand at all :)

Posted

I want to have lisp look-up somehow xref block path name and then it should decide to insert suitable another block (different name) in my drawing.

 

Between all the xref's the only unique name I found was a file path name. I'm trying to retrieve that information somehow and store as variable and then insert another block and fill attributes and so on....

 

Please let me know if I'm still not making sense with this.

Posted

what does this snippet show you

(while (setq a (tblnext "BLOCK" (null a)))
 (if (assoc 1 a)
   (print (cdr (assoc 1 a))
   )
 )
)

Posted

It returns this. Spot on pBe.

 

Command: xtest

"\\drawings\\formats\\b00.dwg" nil

Command:

 

Can you please explain the code? I'm thinking I dont need "while" since there will be one xref block in each drawing. Is this correct?

EDIT :I tried removing while but then it started returning NIL.

 

Now I need to find a way to use this info as a variable and set Cond for all sizes.

Posted
Spot on pBe.

Can you please explain the code? I'm thinking I dont need "while" since there will be one xref block in each drawing. Is this correct?

Now I need to find a way to use this info as a variable and set Cond for all sizes.

 

The way i see it, there are two ways you an do this with vanilla.,

1. Use Tblnext until it finds an xref , only thing is , if the xref were somehow deleted and not purge, the item item will still show on the table

2. Use ssget "X", You still need to iterate thru the selection until it finds an xref.

 

For both options you can use the while function to terminate the loop if xref is found.

 

Now if you combined both and also the using the names of every sheet size block

 

Just for the fun of it, i also wrote a quick code for both

 

(defun xrefet (blk / a f)
 (while (and (setq a (tblnext "BLOCK" (null a)))
      (null f)
 )
   (if	(and (assoc 1 a)
     (wcmatch (cdr (assoc 2 a)) blk)
     (ssget "_X" (list (assoc 2 a)))
)
     (setq f (cdr (assoc 1 a)))
   )
 )
 f
)

 

(XREFET "A00,B00,C00,D00")

 

(defun xrefes (blk / ss i sl a en f)
 (if (and
(setq f	 nil
      i	 -1
      ss (ssget	"_X"
		(list '(0 . "INSERT")
		      (cons 2 blk)
		)
	 )
)
(setq sl (sslength ss))
     )
   (while (and (null f) (< i sl))
     (setq f
     (if (and (setq
		en (cdr (assoc 2 (entget (ssname ss (setq i (1+ i))))))
	      )
	      (setq f (assoc 1 (tblsearch "BLOCK" en)))
	 )
       (cdr f)
       nil
     )
     )
   )
 )
)

 

(XREFES "A00,B00,C00,D00")

 

 

 

Not sure how [XREFET] will fair against [XREFES] but i'm guessing the latter is faster

Posted

pBe,

 

Both the codes returns "; error: too few arguments"

 

I think this line is not working

 
   (if (and (assoc 1 a)
     (wcmatch (cdr (assoc 2 a)) blk)
     (ssget "_X" (list (assoc 2 a)))
)

 

So I removed that line and build my code with cond function. This currently works as is but not sure if this is correct since I removed fool proofing.

 

 
(Defun C:XTEST (/ a f blkname)
 (command "layout" "" "")
 (setvar "cmdecho" 0)
 (setvar "attreq" 0)
 (while (and (setq a (tblnext "BLOCK" (null a)))
      (null f)
 )
   (if (assoc 1 a)
       (setq f (cdr (assoc 1 a)))
   )
 )
 (cond
       ((= f "[url="file://drawings//formats//b00.dwg"]\\drawings\\formats\\b00.dwg[/url]")
(setq blkname "J_Logo_B"))
((= f "[url="file://drawings//formats//c00.dwg"]\\drawings\\formats\\c00.dwg[/url]")
(setq blkname "J_Logo_C"))

((= f "[url="file://drawings//formats//d00.dwg"]\\drawings\\formats\\d00.dwg[/url]")
(setq blkname "J_Logo_D"))

((= f "[url="file://drawings//formats//e00.dwg"]\\drawings\\formats\\e00.dwg[/url]")
(setq blkname "J_Logo_E"))

((= f "[url="file://drawings//formats//j00.dwg"]\\drawings\\formats\\j00.dwg[/url]")
(setq blkname "J_Logo_J"))
 )
  (Command "-INSERT" blkname "0,0" "" "" "")
  (princ "\nSelect Text file for attribute import:")
  (c:attin)
  (setvar "attreq" 1)
  (princ "\nAttributes copied & Updated")
  (command "eattedit" "L")
  (princ)
)

 

Also (setq f (cdr (assoc 1 a))) returns "\\drawings\\formats\\d00.dwg". Due to this, under cond, I had to add full path with .dwg. Is there anyway to return just d00 (not location & not extension)?

 

Thanks,

Posted

pBe,

 

Adding to my last post, the code that I modified only works with a blank new drawing (just with template). If this utility is run on an existing drawing which contains several different blocks, it fails. It seems like its not able to just filter THE xref block from the whole drawing. Please suggest.

Posted
pBe,

Both the codes returns "; error: too few arguments".....

 

Because you did not supply the correct number of arguments

 

(XREFET "A00,B00,C00,D00");

(XREFES "A00,B00,C00,D00");

 

pBe,

.....I had to add full path with .dwg. Is there anyway to return just d00 (not location & not extension)?

 

Demo: (vl-filename-base (getvar 'dwgname))

 

pBe,

 

Adding to my last post, the code that I modified only works with a blank new drawing (just with template). If this utility is run on an existing drawing which contains several different blocks, it fails. It seems like its not able to just filter THE xref block from the whole drawing. Please suggest.

 

Try the code at post # 11 with the correct arguments

 

HTH

Posted

pBe,

 

I think I'm confused. Here is what I understand from this (argument). It looks like that you created a Sub function (is this true?) and then you are calling out subfunction into the main function that time you are adding arguments along with it? And I was making it a part of the main routine. Is it possible the way I was attempting it? Or it has to be thru subfunction?

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...