Issue with IF function

Issue with IF function

Anonymous
Not applicable
2,008 Views
22 Replies
Message 1 of 23

Issue with IF function

Anonymous
Not applicable

I have a smaller part of a larger code, which is a little convoluted. So I'm hoping the issue lies in the smaller part...

 

(defun c:PLOT_CONFIG ()	

(foreach xname (:GetAllXrefNames)
(if (wcmatch (strcase xname) "*TBLOCK*")
(setq lst (cons (substr xname 10 2) lst))
)
)
(vl-load-com) (vlax-for y (vla-get-plotconfigurations (vla-get-activedocument (vlax-get-acad-object))) (if (wcmatch (LM:lst->str lst "") vla-get-name y) (C:Gen-Plot-Single-PDF) (c:PAGE_CONFIG) ) ) )

Is there an obvious issue in the structure I am missing here? Or might I need to expand on the rest of the involved code... 😕

If it is very obvious, please go easy on me. I'm not very use to AutoLISP

0 Likes
Accepted solutions (1)
2,009 Views
22 Replies
Replies (22)
Message 21 of 23

john.uhden
Mentor
Mentor
I remember conquering that in a former life, but I think I left the code
with the company, which offers no help today. I do remember that it was
almost all ActiveX methods and properties.
Hmmm... I did find something on my flash drive that may be of some (?)
value::

;;; Ed Jobe
;;; Sets a Layout to a PlotConfiguration object by
;;; passing a string representing the name of
;;; the Page Setup.
;;; Usage: (SetPlotConfig "PlotConfig_name")

(defun SetPlotConfig (pcname / PlCfg ThisDwg AcadApp)
(setq AcadApp (vlax-get-acad-object)
ThisDwg (vla-get-activedocument AcadApp)
ThisLayout (vla-get-activelayout ThisDwg)
;; Get a valid PlotConfiguration object if it exists
PlCfg (vl-catch-all-apply
'vla-item
(list
(vla-get-PlotConfigurations
ThisDwg
)
pcname
)
)
)
(if (not (vl-catch-all-error-p plcfg))
(vla-copyfrom ThisLayout PlCfg)
)
)

John F. Uhden

0 Likes
Message 22 of 23

Anonymous
Not applicable

Thanks John.

 

Minor adjustments. 

I was getting bad argument errors again so I added an 'else' option to the 'if' line. 

And I added an 'if' to account for nil return on PageSetupName. 

 

 

(foreach tab (layoutlist)
	(setvar "ctab" tab)

  (setq layout (getvar "ctab"))													
  (setq dn (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT"))))
  (setq laydict (dictsearch dn layout))
  (setq psn (member '(100 . "AcDbPlotSettings") laydict))
  (if (= (caadr psn) 1)			
    (setq psn (cdadr psn))     ;psn = PageSetupName
    (setq psn " ")	                                                    ;added 'else' here	
  )
	
	(if (= psn 0)                                                       ;added 'if nil' here
		(progn (c:PAGE_CONFIG_SINGLE)(C:Plot_PDF_SingleTab))
		(if (wcmatch (strcase psn) (strcat "*" (strcase ps) "*"))				
			(C:Plot_PDF_SingleTab)
			(progn (c:PAGE_CONFIG_SINGLE)(C:Plot_PDF_SingleTab))
		);if
	)
);foreach
)	

 

 

0 Likes
Message 23 of 23

john.uhden
Mentor
Mentor
You might like to consider using the technique I learned from Stephan
Koster years ago.
You don't necessarily have to use IF.
If you want your program to flow until something evaluates to nil
,then...
(and
(or
(findfile "myfile.lsp")
(prompt "\nCan't find myfile.lsp")
)
(or
(= (getvar "dwgtitled") 1)
(prompt "\nDrawing has not been saved.")
)
;; etc.
) ;; end and

You should know that (prompt ...) always returns nil

John F. Uhden

0 Likes