FOREACH element returned from a list run a LISP

FOREACH element returned from a list run a LISP

wales123456
Contributor Contributor
2,581 Views
3 Replies
Message 1 of 4

FOREACH element returned from a list run a LISP

wales123456
Contributor
Contributor

Hello everyone..

Hope you are all having a good day...

 

I have tried to come up / merge code to run a LISP on a returned list (Thanks Lee Mac for the Getfiles function) but am not sure how to merge it.
(my head is bursting already)

 

my code is:

 

(defun titleblock(aNme / bNme lay ss att e)
  (vl-load-com)
  (if (or (not aNme) (/= aNma ""))
  (progn
  (setq	bNme "*Drwg title*")
  (setq e "")
  (setq lay	(getvar "ctab"))
    (if	(and (not (eq "MODEL" (strcase lay)));;If not model and has block bnme inserts
	     (setq ss (ssget "_X"
			     (list (cons 0 "INSERT")
				   (cons 2 bNme)
				   (cons 66 1)
				   (cons 410 lay)
			     )
		      )
	     )
	  )
      ;;for each attribute in the first block bnme in selection ss
	  (progn
      (foreach att (vlax-invoke
		     (vlax-ename->vla-object (ssname ss 0))
		     'GetAttributes
		   )
	     (if	  (apply 'eq (mapcar 'strcase (list aNme (vla-get-TagString att))))
	     (setq e (vla-get-TextString att))
	     ) 
	  )
	  )
    )
	(if (not (eq e ""))
	  (setq e e)
	  (setq e "")
	)
	)
	(setq e nil)
	)
  )
  
  

(defun c:pdf ()
	(foreach n (LM:getfiles "Select Drawings" "" "dwg")
		(setvar "wipeoutframe" 0)
			(Command "undo" "m")
			(Setq nm (strcat (getvar "dwgprefix") "Issue\\" (titleblock "R10") "_" (titleblock "R11") "-" (titleblock "R1") " " (titleblock "R2") " " (titleblock "R3") " " (titleblock "R4")));<<<PDF Directory
			(Command "-plot" "y" "" "DWG TO PDF.PC3" "ISO full bleed A0 (841.00 x 1189.00 MM)" "m" "l" "n" "w" "0,0" "1189,841" "1=1" "c" "y" "Normal-added.ctb" "y" "y" "n" "n" nm "n" "y")
	)
)
(defun c:pdfs ()
(setvar "wipeoutframe" 0) 
(foreach layout (layoutlist)
	(setvar "ctab" layout)
	(Setq nm (strcat (getvar "dwgprefix") "Issue\\" (titleblock "R10") "_" (titleblock "R11") "-" (titleblock "R1") " " (titleblock "R2") " " (titleblock "R3") " " (titleblock "R4")));<<<PDF Directory
	(Command "-plot" "y" "" "DWG TO PDF.PC3" "ISO full bleed A0 (841.00 x 1189.00 MM)" "m" "l" "n" "w" "0,0" "1189,841" "1=1" "c" "y" "Normal-added.ctb" "y" "y" "n" "n" nm "n" "y")
	))

and if I include LM:getfiles within my startup, I don't understand why it cannot run c:pdf on the list returned..?

 

I get an error saying:

 

Enter a layout name or [?] <Model>: Enter an output device name or [?] <DWFx ePlot (XPS Compatible).pc3>: DWG TO PDF.PC3 Enter paper size or [?] <ISO full bleed A1 (841.00 x 594.00 MM)>: ISO full bleed A0 (841.00 x 1189.00 MM) Enter paper units [Inches/Millimeters] <Millimeters>: m Enter drawing orientation [Portrait/Landscape] <Landscape>: l Plot upside down? [Yes/No] <No>: n Enter plot area [Display/Extents/Limits/View/Window] <Display>: w Enter lower left corner of window <259147.651703,208410.269836>: 0,0 Enter upper right corner of window <259147.651703,208410.269836>: 1189,841 Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit] <Fit>: 1=1 Enter plot offset (x,y) or [Center] <0.00,0.00>: c Plot with plot styles? [Yes/No] <Yes>: y Enter plot style table name or [?] (enter . for none) <>: Normal-added.ctb Plot with lineweights? [Yes/No] <Yes>: y Enter shade plot setting [As displayed/legacy Wireframe/legacy Hidden/Visual styles/Rendered] <As displayed>: y
Enter file name <Drawing2-Model.pdf>: n Save changes to page setup [Yes/No]? <N> n Proceed with plot [Yes/No] <Y>: C:\Program Files\Autodesk\AutoCAD 2017\Issue\_-
Yes or No, please.
; error: Function cancelled
Proceed with plot [Yes/No] <Y>: *Cancel*

 

which I understand means it is not obtaining variable nm but am very confused as to why?

 

Also, does anyone know if I can build in BACKGROUNDPLOT as 3 to force the PDFing to run in the background.

 

Hopefully someone will be able to help?

 

Thanks

 

Steve

0 Likes
2,582 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

....
  (if (or (not aNme) (/= aNma ""))
....

....

I get an error saying:

.... Proceed with plot [Yes/No] <Y>: C:\Program Files\Autodesk\AutoCAD 2017\Issue\_-
Yes or No, please.
; error: Function cancelled
Proceed with plot [Yes/No] <Y>: *Cancel*

 

which I understand means it is not obtaining variable nm but am very confused as to why?

....


It looks to me as though you're not providing a Yes/No answer asked for, presumably before the nm variable should be fed in.  Double-check the prompt sequence and exact sequence of appropriate supplied answers.

 

Also, should that code line quoted above be:

 

....
  (if (or (not aNme) (/= aNme ""))
....

 

?

Kent Cooper, AIA
Message 3 of 4

dbroad
Mentor
Mentor

Not having your drawing files, I got a little lost in your logic.

 

As @Kent1Cooper indicated, the if statement in titleblock is puzzling

 

Shouldn't you be checking if aNme exists, is a string, and is not just a empty string?  If so, that test doesn't do it.  You are checking to see if it doesn't exist or is not an empty string.

 

(if (and (eq (type aNme) 'str) (/= aNme ""))

(progn

  ;;do stuff that works with aNme

)

 (progn

;;else do stuff that explains the error or works around the problem.

 )

 

Reading your command returns, it looks like you've got your arguments out of place.  You forgot to answer the shade plot setting, answered "y" to the name of the file, and then answered with the filename when asked if the plot should proceed.

 

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 4 of 4

martti.halminen
Collaborator
Collaborator

 

If the idea was to type PDF on the command line, and have AutoCAD prompt you for several filenames, and plot all of those as .pdf, you have a few higher-level problems in addition to the details that are crashing your program.

 

First, your FOREACH call goes through each item of the list returned by (LM:getfiles ...), with the variable N bound to that item, calling whatever is defined in the body of the call. The trouble is, nowhere in the body is N referenced, so if you pick three filenames, you are only plotting the current drawing three times.

 

Which leads us to the bigger problem: normally each drawing has its own Lisp environment, so you can't jump into another drawing inside a Lisp program and continue running the same program. There are some ways around this in AutoLISP, though not very convenient or simple.More common is using an outside program to control operating on the drawings; either write it yourself, use ScriptPro or search for some third-party program doing what you need.

 

--