Issue with IF function

Issue with IF function

Anonymous
Not applicable
2,004 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,005 Views
22 Replies
Replies (22)
Message 2 of 23

dbhunia
Advisor
Advisor

I think it should be here..... (else post more code)

 


(defun c:PLOT_CONFIG ()	

(foreach xname (C: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) ) ) )

 


 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 23

Anonymous
Not applicable

Unfortunately that was not it. Here is the rest. It all works - except for the initially mentioned section.

(defun C:Gen-Plot-Single-PDF (/ savepath tab dname)

			(setvar "filedia" 0)
  
	(setq savepath (strcat (getvar "DWGPREFIX") "ProgressPrints\\"))
  
	(setq PathTest (C:Gen-CreateDirectory savepath))

  	(if (= PathTest T)
	(progn  
  		(foreach tab (layoutlist)
	  		(if (= (length (layoutlist)) 1)
				(setq	dname (strcat savepath (vl-string-subst (strcat " " tab) ".dwg" (getvar "dwgname"))))
				(setq	dname (strcat savepath (vl-string-subst (strcat "-" tab) ".dwg" (getvar "dwgname"))))
			)
    			(setvar "ctab" tab)
	  					
			(if (wcmatch (strcase (getvar "dwgname")) "*-CO-*")
	 		 (command "-plot" "y" tab "DWG to PDF.pc3" "" "m" "l" "n" "l" "" "" "y" "" "y" "n" "n" "n" dname "n" "y")
				(command "-plot" "y" tab "DWG to PDF.pc3" "" "m" "l" "n" "l" "" "" "y" "" "y" "n" "n" "n" dname "n" "y")
			);SOLVE: if theres eror = prompt 
		)
	  );progn
	(princ "Failed to create folder path. Please create \"ProgressPrints\" file path manually in build folder")
	);if
  		(setvar "filedia" 1)
  	(princ)
);defun

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Essential functions established for PAGE_CONFIG function.

(defun c:GetAllXrefNames  (/ blk lst)
  (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (if (eq (vla-get-isXref blk) :vlax-true)
      (setq lst (cons (vla-get-name blk) lst))))
  lst
)

(defun LM:lst->str ( lst del ) 
    (if (cdr lst) 
        (strcat (car lst) del (LM:lst->str (cdr lst) del))
        (car lst) 
    )  
) 

;;;;;;;;

(defun c:PAGE_CONFIG (/ y xname lst psetup)		

    (vl-load-com)
	(vlax-for y (vla-get-plotconfigurations
    (vla-get-activedocument (vlax-get-acad-object)))
		(if (/= "Model" (vla-get-name y))				
			(vla-delete y)
		)
    )
											
  (foreach xname (c:GetAllXrefNames)
    (if (wcmatch (strcase xname) "*TBLOCK*")
      (setq lst (cons (substr xname 10 2) lst))
	)
   )
   
   (if (wcmatch (strcase (getvar "dwgname")) "*-CO-*")
	 		 (setq psetup (strcat (LM:lst->str lst "") " - Colour - Full Size"))
				(setq psetup (strcat (LM:lst->str lst "") " - Mono - Full Size"))
	)
   
(command "_.psetupin" "C:/Apps/_Cad/2017_BU/BU/Templates/_CDD_MEP_PageSetUps.dwt" psetup) 
	
	(foreach layout (layoutlist)
		(setvar "ctab" layout)
		(COMMAND "-PLOT" "" "" psetup "" "NO" "YES" "NO")
	 (C:ZE)
	 )
	
	(princ)   
 )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:PLOT_CONFIG ()	

(foreach xname (c: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) 																	
		)															
    )																
)

 

0 Likes
Message 4 of 23

dbhunia
Advisor
Advisor

Make this Change...

 

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

 

And check <THIS> and <THIS>

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 23

Anonymous
Not applicable

That definitely did something!!

 

It's still not really working though... as oppose to Plotting it just goes through Regenerating the views?


0 Likes
Message 6 of 23

john.uhden
Mentor
Mentor

Nice pick-up.

The only suggestion I see is that one must not assume that all named thingies are either upper case or lower case.  When I do string comparisons of named table objects, I almost always convert the name and the match string to uppercase.

John F. Uhden

0 Likes
Message 7 of 23

Anonymous
Not applicable

Hmm.. speaking of matching, maybe the problem is i need some sort of WildCard feature?

For example,  (LM:lst->str lst "") should = B1
& (vla-get-name y) should =X-TBLOCK-B1-H

 

So I don't think upper/lower case should be a problem,  just need it to see if B1 is in the xref name...

0 Likes
Message 8 of 23

john.uhden
Mentor
Mentor
I would still change the comparison to uppercase.
Then if the match is "B1" (or even "b1"), then
(wcmatch (strcase (vla-get-name y)) (strcat "*" (strcase match) "*"))
or if the hyphens matter, then
(wcmatch (strcase (vla-get-name y)) (strcat "*-" (strcase match) "-*"))

BTW, where I am working now *[yay... I'm working!]*
they have no regard for case in naming layers or blocks. Their conventions
are consistently random.

<>
Virus-free.
www.avg.com
<>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

John F. Uhden

0 Likes
Message 9 of 23

Anonymous
Not applicable

Ok, thanks for the advice! I guess it would be sensible to take that precaution. 

 

I loaded it in and assume it should look like this? However it's returning "bad argument type: stringp nil" now..

(vlax-for y (vla-get-plotconfigurations (vla-get-activedocument (vlax-get-acad-object)))
(if (wcmatch (strcase (vla-get-name y)) (strcat "*" (strcase match(LM:lst->str lst "")) "*"))
(C:Gen-Plot-Single-PDF)
(c:PAGE_CONFIG)
)
)

0 Likes
Message 10 of 23

john.uhden
Mentor
Mentor
I am not familiar with the function, but my guess is that (LM:lst->str lst
"") returns a delimited string that is somehow not compatible with the rest
of the code. But what do I know. Tony T called me a pea=brain. I think
it was back in the Compuserve days.
Maybe you would be better off iterating through the lst.

John F. Uhden

0 Likes
Message 11 of 23

Anonymous
Not applicable

Well at least peas have the capacity to grow. 

Yea i have a feeling all my problems, present & future will be coming from that lst function. I think I need to re-think the whole thing. I feel like it doesn't need to be complicated I just wanted to extract a couple of letters from an xref!

Thanks anyway for your help.

0 Likes
Message 12 of 23

Anonymous
Not applicable

Ok! I tidied up my code (with the help of dbhunia).  I'm almost there!

(foreach tab (layoutlist)
	(setvar "ctab" tab)
	  					
	(vl-load-com)
	(vlax-for y (vla-get-plotconfigurations (vla-get-activedocument (vlax-get-acad-object)))
		(if (wcmatch (strcase (vla-get-name y)) (strcat "*" (strcase ps) "*"))	           ;if match		
			(C:Gen-Plot-Single-PDF)	                                                   ;call this function
			(c:PAGE_CONFIG C:Gen-Plot-Single-PDF)                                      ;else call this function &then this function																	
		)															
	)																
)

It's working in as far as if there is a match it proceeds with calling the first function. But if there is no match (or no configuration detected to match with), it doesn't proceed with calling the second line of functions. it just returns "nil".

 

Thoughts on how to fix? Perhaps I need a line saying "else is 'nil', run these functions"? Or would that be a bit dodgy..

0 Likes
Message 13 of 23

Anonymous
Not applicable

 

So I solved the issue with my 'else' line. Weird how it runs the last function first 2nd(C:Gen-Plot-Single-PDF) 1st(c:PAGE_CONFIG)).

Still not sure how to run a function for if there is no Configuration though. 

	(vl-load-com)
	(vlax-for y (vla-get-plotconfigurations (vla-get-activedocument (vlax-get-acad-object)))
		(if (wcmatch (strcase (vla-get-name y)) (strcat "*" (strcase ps) "*"))				
			(C:Gen-Plot-Single-PDF)												
			((C:Gen-Plot-Single-PDF)(c:PAGE_CONFIG))
		)
		(if (vlax-for y (vla-get-plotconfigurations (vla-get-activedocument (vlax-get-acad-object)))) nil
			(c:PAGE_CONFIG)
		)
	)

This makes sense to me, or to replace "nil" with "<None>", but coincidentally, none of these are working 😕

 

0 Likes
Message 14 of 23

dbhunia
Advisor
Advisor
Accepted solution

check <<This>>

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 15 of 23

Anonymous
Not applicable

GREAT!! dbhunia to the rescue again!

You are my favourite person at the moment, thanks for your guidance! 

0 Likes
Message 16 of 23

Anonymous
Not applicable

I'm trying. I really am..

;(foreach tab (layoutlist)
;	(setvar "ctab" tab)
	  					
	(vl-load-com)
	
	(setq acadObj (vlax-get-acad-object))
        (setq doc (vla-get-ActiveDocument acadObj))
        (setq PlotConfigurations (vla-get-PlotConfigurations doc))
    
    (if (= (vla-get-Count PlotConfigurations) 0)
        ((C:Gen-Plot-Single-PDF)(c:PAGE_CONFIG))
		(vlax-for y (vla-get-plotconfigurations (vla-get-activedocument (vlax-get-acad-object)))
			(if (wcmatch (strcase (vla-get-name y)) (strcat "*" (strcase ps) "*"))				
				(C:Gen-Plot-Single-PDF)												
				((C:Gen-Plot-Single-PDF)(c:PAGE_CONFIG))
			);if
		);vlax
	);if	
);foreach

I've put all the code together and it kind of works. I've tried different sorts of arrangements but it keeps saying "bad argument".. and then when I activate the 'for each tab' it jumps to the end tab and only plots that one. 

 

What's so bad about my argument?? I feel offended

0 Likes
Message 17 of 23

john.uhden
Mentor
Mentor

Part of your problem may be your construction.

You can't do:

((C:Gen-Plot-Single-PDF)(c:PAGE_CONFIG))

Instead, you must do:

(progn (C:Gen-Plot-Single-PDF)(c:PAGE_CONFIG))

John F. Uhden

0 Likes
Message 18 of 23

john.uhden
Mentor
Mentor
In my example I used a string variable named match.
You used it as well, but apparently with no value. You appear to be using
ps instead.
So, get rid of the term match...
BAD: (if (wcmatch (strcase (vla-get-name y)) (strcat "*" (strcase match ps)
"*"))
GOOD: (if (wcmatch (strcase (vla-get-name y)) (strcat "*" (strcase ps)
"*"))

John F. Uhden

0 Likes
Message 19 of 23

Anonymous
Not applicable

john.uhden yes if you see my revised code I did make that change with the 'match', and thanks for the correction with the '(progn'. 

 

The "bad function" has gone now and it works fine for one layout. But as soon as I activate the 'foreach tab' lines, things start getting messy. I have a feeling it has to do with how i'm getting 'PlotConfigurations' as oppose to 'Current Page Setup'..

0 Likes
Message 20 of 23

Anonymous
Not applicable

Hooray. This works. Replaced ConfigurationName with PageSetupName.

 

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

  (setq tab (getvar "ctab"))
  (setq dn (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT"))))
  (setq laydict (dictsearch dn tab))
  (setq psn (member '(100 . "AcDbPlotSettings") laydict))
  (if (= (caadr psn) 1)			
    (setq psn (cdadr psn))				;psn = PageSetupName
  )
			
    (if (wcmatch (strcase psn) (strcat "*" (strcase ps) "*"))				
				(C:Gen-Plot-Single-PDF)
				(progn (c:PAGE_CONFIG)(C:Gen-Plot-Single-PDF))
    );if
	
);foreach

)			
0 Likes