LISP Attribute Extraction Assistance

LISP Attribute Extraction Assistance

carl_swanGU3NV
Participant Participant
143 Views
7 Replies
Message 1 of 8

LISP Attribute Extraction Assistance

carl_swanGU3NV
Participant
Participant

Hi all,

I could really use some help with a LISP that I'm trying to write. I need to speed up my plotting, and I want to plot PDF's with filenames derived from attributes in the titleblock.

 

So far I've managed to get the lisp cycling through the layouts and plotting each correctly, but despite my best efforts I cannot extract the attribute information. I've tried Lee-Mac's examples, and countless others....but the results continue to elude me. I just don't understand the syntax enough/correctly.

 

If anyone could help out I'd very much appreciate it.

 

Info:

I have multiple (number varies) paperspace layouts within a drawing.

 

Each layout has a titleblock called "Title" containing a number of attributes (the titleblock name and tag names are fixed and never change).

 

I need to extract four of the attributes (lets call them A, B, C and D) and use them for the filename of the PDF, which needs to be in the format "A - B - C - D".

 

I need to cycle through the layouts, plotting a PDF for each.

 

The code below is what I have so far. It works fine, but I just need to get "pdfname = A - B - C - D" populated with the attributes

 

 

(defun c:PlotAllSheets ()				;LISP name
  (foreach lay (layoutlist)				;Cycle through all layouts

  pdfname = A - B - C - D

  (setvar 'CTab lay)
  (COMMAND 	"-PLOT"					;Invoke plot command
	"Y"						;Detailed plot configuration?
	""						;Layout name
	"AutoCAD PDF (General Documentation).pc3"	;Output device
	"ISO Full Bleed A1 (841.00 x 594.00 MM)"	;Paper size 
	"M"						;Paper units
	"L"						;Drawing orientation
	"N"						;Upside down
	"W"						;Window
	"1.1638,568.0192"				;Window start coordinates
	"823.2229,-11.1902"				;Window end coordinates
	"1:1"						;Plot scale
	"C"						;Center
	"N"						;Plot with plot style
	"monochrome.ctb"				;Plot style
	"Y"						;Plot line weights
	"N"						;Plot line scaling
	"N"						;Paper space first
	"N"						;Hide? 
	pdfname						;Name of file
	"N"						;Directory to save
	"y")						;Save changes to page setup
  )
)

 

@Moshe-A    @pendean @patrick_35 

0 Likes
144 Views
7 Replies
Replies (7)
Message 2 of 8

kajanthangavel
Advocate
Advocate

Can you post a sample drawing? Preferably, a drawing with a title block that includes attributes.

0 Likes
Message 3 of 8

paullimapa
Mentor
Mentor

Please provide sample dwg with the title block and the attribute tag names you want to extract A, B, C and D


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 8

carl_swanGU3NV
Participant
Participant

@paullimapa @kajanthangavel 

 

Thanks for taking the time to look into this for me, it's very much appreciated.

 

I've attached a template, but I've stripped out everything else other than the attributes required (there are more attributes in the titleblock, but I need to keep the file confidential). 

 

The naming convention for the PDF's needs to be "Drawing Number - REV - ID - Description Top - Description bottom". The space either side of the hyphen is required.

 

Thanks again 🙂

0 Likes
Message 5 of 8

paullimapa
Mentor
Mentor

Try the attached revised lisp.

Basically I added the following:

1) Localized variables:

  (/ blkname dwgprefix dwgname en pdfname ss) ; localize variables

2) 

  ; set blkname, separator & tagnames
  (setq blkname "Titleblock"
        sep " - "
        taga "DRAWING-NUMBER"
        tagb "REV"
        tagc "J-NUM"
        tagd "DESCRIPTION-TOP"
        tage "DESCRIPTION-BOT"
        dwgprefix (getvar "dwgprefix") 
        dwgname (vl-filename-base (getvar "dwgname"))
  )

3) 

   ; find block in layout & get pdfname
  (if (setq ss (ssget "_X" (list '(0 . "Insert") '(66 . 1) (cons 2 blkname) (cons 410 lay))))
    (setq ; then if found
      en (ssname ss 0)  ; get entity name
      pdfname ;  pdfname = A - B - C - D
       (strcat
         dwgprefix 
         (getpropertyvalue en taga) 
         sep 
         (getpropertyvalue en tagb) 
         sep 
         (getpropertyvalue en tagc) 
         sep 
         (getpropertyvalue en tagd) 
         sep 
         (getpropertyvalue en tage) 
         ".pdf"
       )
    ) ; setq       
    (setq pdfname (strcat dwgprefix dwgname sep lay ".pdf")) ; else when no blk found in layout
  ) ; if

4) Don't need to set layout current since response can be placed inside Plot sequence:

;  (setvar 'CTab lay)
  (COMMAND 	"-PLOT"					;Invoke plot command
	"Y"						;Detailed plot configuration?
  lay           ;Layout name
;	""						;Layout name

5) 

  (princ) ; clean exit
) ; defun

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 8

carl_swanGU3NV
Participant
Participant

@paullimapa 

 

This is amazing thank you so much for taking the time to help me!

 

It's 99% there, I just need one small change, which is the hyphen between description top and description bottom. Could you please remove the hyphen and just make it a simple space between these two attributes?

 

Also, if it's not too much trouble, are you able to create another version of it that just plots the layout that's currently active, rather than all of them? I can see it being very useful and I hadn't thought of it up until now. I'm assuming that it's simply the removal of line 18 (I'm trying to understand you're code but it's significantly above my understanding and I don't want to butcher your hard work!

 

Thanks again 😄

0 Likes
Message 7 of 8

paullimapa
Mentor
Mentor

see attached lisp files


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

Another but needs title block to be of a fixed name and also at 0,0. It allows you to select a range of layouts as you mentioned not plot all, Put in 1 then 99 as last will plot all. You will need to edit to suit your request.

SeaHaven_0-1755046130349.png

 

 

 

0 Likes