Going to go Insane

Going to go Insane

My_Civil_3D
Advocate Advocate
795 Views
14 Replies
Message 1 of 15

Going to go Insane

My_Civil_3D
Advocate
Advocate

Hi guys, i am going to go insane. when i load my code from a lisp file its giving me an error: to few arguments. but when i copy the whole lisp over to autocad's lisp editor and load it that way it works perfectly fine. Surely something is werid here. here is my code:

 

(defun c:C_TBRN (/ s e c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 )

(setq s (ssget "_x" '((0 . "INSERT") (2 . "Title Block") (8 . ".DRAWING-SHEET"))))
(setq e (ssname s 0))
(setq c0 (getpropertyvalue e "REV0"))
(setq c1 (getpropertyvalue e "REV1"))
(setq c2 (getpropertyvalue e "REV2"))
(setq c3 (getpropertyvalue e "REV3"))
(setq c4 (getpropertyvalue e "REV4"))
(setq c5 (getpropertyvalue e "REV5"))
(setq c6 (getpropertyvalue e "REV6"))
(setq c7 (getpropertyvalue e "REV7"))
(setq c8 (getpropertyvalue e "REV8"))
(setq c9 (getpropertyvalue e "REV9"))
(setq c10 (getpropertyvalue e "REV10"))
(setq c11 (getpropertyvalue e "REV11"))

(setq r1 (getstring T "\nEnter Revision: "))
(setq r2 (getstring T "\nEnter Revision By: "))
(setq r3 (getstring T "\nEnter Revision Date: "))
(setq r4 (getstring T "\nEnter Revision Description: "))

(if (= c0 "")
	(progn
	(setpropertyvalue e "REV0" r1)
	(setpropertyvalue e "0BY" r2)
	(setpropertyvalue e "DATE0" r3)
	(setpropertyvalue e "DESCRIPTION-0" r4)
	(princ))
	
	(progn
	(princ)
	(if (= c1 "")
	(progn
	(setpropertyvalue e "REV1" r1)
	(setpropertyvalue e "1BY" r2)
	(setpropertyvalue e "DATE1" r3)
	(setpropertyvalue e "DESCRIPTION-1" r4)
	(princ))
	
(progn
	(princ)
	(if (= c2 "")
	(progn
	(setpropertyvalue e "REV2" r1)
	(setpropertyvalue e "2BY" r2)
	(setpropertyvalue e "DATE2" r3)
	(setpropertyvalue e "DESCRIPTION-2" r4)
	(princ))
	
(progn
	(princ)
	(if (= c3 "")
	(progn
	(setpropertyvalue e "REV3" r1)
	(setpropertyvalue e "3BY" r2)
	(setpropertyvalue e "DATE3" r3)
	(setpropertyvalue e "DESCRIPTION-3" r4)
	(princ))
	
(progn
	(princ)
	(if (= c4 "")
	(progn
	(setpropertyvalue e "REV4" r1)
	(setpropertyvalue e "4BY" r2)
	(setpropertyvalue e "DATE4" r3)
	(setpropertyvalue e "DESCRIPTION-4" r4)
	(princ))
	
(progn
	(princ)
	(if (= c5 "")
	(progn
	(setpropertyvalue e "REV5" r1)
	(setpropertyvalue e "5BY" r2)
	(setpropertyvalue e "DATE5" r3)
	(setpropertyvalue e "DESCRIPTION-5" r4)
	(princ))	
	
(progn
	(princ)
	(if (= c6 "")
	(progn
	(setpropertyvalue e "REV6" r1)
	(setpropertyvalue e "6BY" r2)
	(setpropertyvalue e "DATE6" r3)
	(setpropertyvalue e "DESCRIPTION-6" r4)
	(princ))
	
(progn
	(princ)
	(if (= c7 "")
	(progn
	(setpropertyvalue e "REV7" r1)
	(setpropertyvalue e "7BY" r2)
	(setpropertyvalue e "DATE7" r3)
	(setpropertyvalue e "DESCRIPTION-7" r4)
	(princ))

(progn
	(princ)
	(if (= c8 "")
	(progn
	(setpropertyvalue e "REV8" r1)
	(setpropertyvalue e "8BY" r2)
	(setpropertyvalue e "DATE8" r3)
	(setpropertyvalue e "DESCRIPTION-8" r4)
	(princ))

(progn
	(princ)
	(if (= c9 "")
	(progn
	(setpropertyvalue e "REV9" r1)
	(setpropertyvalue e "9BY" r2)
	(setpropertyvalue e "DATE9" r3)
	(setpropertyvalue e "DESCRIPTION-9" r4)
	(princ))

(progn
	(princ)
	(if (= c10 "")
	(progn
	(setpropertyvalue e "REV10" r1)
	(setpropertyvalue e "10BY" r2)
	(setpropertyvalue e "DATE10" r3)
	(setpropertyvalue e "DESCRIPTION-10" r4)
	(princ))

(progn
	(princ)
	(if (= c11 "")
	(progn
	(setpropertyvalue e "REV11" r1)
	(setpropertyvalue e "11BY" r2)
	(setpropertyvalue e "DATE11" r3)
	(setpropertyvalue e "DESCRIPTION-11" r4)
	(princ))
	
(progn
	(princ)
	(if (= c11 "")
	(progn
	(setpropertyvalue e "REV12" r1)
	(setpropertyvalue e "12BY" r2)
	(setpropertyvalue e "DATE12" r3)
	(setpropertyvalue e "DESCRIPTION-12" r4)
	(princ))
	(progn
	(princ)))))))))))))))))))))))))))
	(prompt "\nRevision info has been updated Successfully!")
	(princ)
	)
Civil 3D Certified Professional
0 Likes
Accepted solutions (2)
796 Views
14 Replies
Replies (14)
Message 2 of 15

ronjonp
Mentor
Mentor

Loads fine here. You should really look into the use of COND.

After looking at all the nested IF statements, COND is not what you need because it will stop evaluating when a condition is met and the IF statements continue to the end.

Nevermind .. my brain was working backwards. 😂

0 Likes
Message 3 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

This is a perfect case for COND... nice and easy.

 

It goes like this... is c0=""? no? then is c1=""? no? then is c2="" Yes! go for it! Once there is some func tested True, it does not even test all the rest and leaves the COND entirely.

 

 

  (cond
    ((= c0 "")
     (setpropertyvalue e "REV0" r1)
     (setpropertyvalue e "0BY" r2)
     (setpropertyvalue e "DATE0" r3)
     (setpropertyvalue e "DESCRIPTION-0" r4)
     )
    
    ((= c1 "")
     (setpropertyvalue e "REV1" r1)
     (setpropertyvalue e "1BY" r2)
     (setpropertyvalue e "DATE1" r3)
     (setpropertyvalue e "DESCRIPTION-1" r4)
     )
    
    ((= c2 "")
     (setpropertyvalue e "REV2" r1)
     (setpropertyvalue e "2BY" r2)
     (setpropertyvalue e "DATE2" r3)
     (setpropertyvalue e "DESCRIPTION-2" r4)
     )
    ....

 

0 Likes
Message 4 of 15

paullimapa
Mentor
Mentor

keep in mind that the if function can only have max two progn like this:

(if

 (progn

 ) ; true then

 (progn

 ) ; else false

) ; end if

(


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

ronjonp
Mentor
Mentor
Accepted solution

@My_Civil_3D 

See if you can learn from this reorganization of your code. It should accomplish the same thing.

 

(defun c:c_tbrn	(/ e f n r1 r2 r3 r4 s)
  (if ;; Always check that you are passing ALL the needed data \ objects
      (and (setq s (ssget "_X" '((0 . "INSERT") (2 . "Title Block") (8 . ".DRAWING-SHEET"))))
	   (setq e (ssname s 0))
	   (setq r1 (getstring t "\nEnter Revision: "))
	   (setq r2 (getstring t "\nEnter Revision By: "))
	   (setq r3 (getstring t "\nEnter Revision Date: "))
	   (setq r4 (getstring t "\nEnter Revision Description: "))
      )
    (progn (foreach att	'("REV0" "REV1"	"REV2" "REV3" "REV4" "REV5" "REV6" "REV7" "REV8" "REV9"
			  "REV10" "REV11")
	     ;; Strip "REV" to get the number
	     (setq n (substr att 4))
	     (if (and (not f) (setq f (= "" (getpropertyvalue e att))))
	       (progn (setpropertyvalue e att r1)
		      ;; Combine 'n' with 'BY', 'DATE' and 'DESCRIPTION-' to set the correct attribute values
		      (setpropertyvalue e (strcat n "BY") r2)
		      (setpropertyvalue e (strcat "DATE" n) r3)
		      (setpropertyvalue e (strcat "DESCRIPTION-" n) r4)
	       )
	     )
	   )
	   (princ "\nRevision info has been updated Successfully!")
    )
    (princ "\nTitleblock not found!")
  )
  (princ)
)

 

 

*Added a flag variable to stop setting attributes once set.

 

 

 

 

 

0 Likes
Message 6 of 15

Kent1Cooper
Consultant
Consultant

@paullimapa wrote:

keep in mind that the if function can only have max two progn ....


I think [without breaking it down to study in detail] that they're not violating that, but that it's a bunch of nested (if) functions, and within each 'else' argument (progn) wrapper is another (if) function with its own 'then' and 'else' (progn) wrappers, and so on....  Gotta love that line 151, where all of those are collectively wrapped up -- I don't think I've ever seen 27 parentheses in a row before!

Kent Cooper, AIA
0 Likes
Message 7 of 15

ВeekeeCZ
Consultant
Consultant

My impression is that it should fill up just the first one free.

0 Likes
Message 8 of 15

ronjonp
Mentor
Mentor

@ВeekeeCZ wrote:

My impression is that it should fill up just the first one free.


Agreed. I modified my post and code.

0 Likes
Message 9 of 15

Kent1Cooper
Consultant
Consultant

My suggestion [untested]:

 

(defun c:C_TBRN (/ s e n)
  (setq
    s (ssget "_x" '((0 . "INSERT") (2 . "Title Block") (8 . ".DRAWING-SHEET")))
    e (ssname s 0)
    n 0
  )
  (while (/= (getpropertyvalue e (strcat "REV" (itoa n))) ""); Rev{n} already used
    (setq n (1+ n)); increment up to check next one until an unused one
  ); while
  (setq n (itoa n)); text equivalent
  (setpropertyvalue e (strcat "REV" n) (getstring T "\nEnter Revision: "))
  (setpropertyvalue e (strcat n "BY") (getstring T "\nEnter Revision By: "))
  (setpropertyvalue e (strcat "DATE" n) (getstring T "\nEnter Revision Date: "))
  (setpropertyvalue e (strcat "DESCRIPTION-" n) (getstring T "\nEnter Revision Description: "))
  (prompt "\nRevision info has been updated Successfully!")
  (princ)
)

 

In addition to using less code, it allows the series to continue beyond any limit on the Revision number, without having to build in what-to-do elements for Revisions beyond 11.  EDIT:  [Though I now realize there's the limitation imposed by the Attributes present in the Block definition....]

Kent Cooper, AIA
0 Likes
Message 10 of 15

ronjonp
Mentor
Mentor

@Kent1Cooper I like the thought process :).

 

I'd put an error check in the getproperty value like so. I doubt that there are an infinite number of revision attributes and when they all fill up BOOM!

(while (and (not (setq f (vl-catch-all-error-p
			   (vl-catch-all-apply 'getpropertyvalue (list e (strcat "REV" (itoa n))))
			 )
		 )
	    )
	    (/= (getpropertyvalue e (strcat "REV" (itoa n))) "")
       )				; Rev{n} already used
  (setq n (1+ n))			; increment up to check next one until an unused one
)					; while
(if f
  (alert "SOMETHING WENT VERY WRONG!")
)

 

0 Likes
Message 11 of 15

Kent1Cooper
Consultant
Consultant

Not a bad idea.  I'd be inclined to make the alert say something less panicky, like:

"Block requires additional Attribute(s) for higher Revision number(s)."

It may also be worth adding a check on whether it found that Block in the first place, so that it could inform the User with a prompt or alert, rather than rely on an error message that would be more cryptic.

Kent Cooper, AIA
0 Likes
Message 12 of 15

ronjonp
Mentor
Mentor

The alert was just for fun 8-) and I agree checking for the titleblock is key. See HERE.

0 Likes
Message 13 of 15

My_Civil_3D
Advocate
Advocate

I appreciate all the help given from others but making fun of someone learning just shows the person you are. instead of helping in a proper way you decide to intimidate me further, if i'm not struggling enough like it is.

Civil 3D Certified Professional
0 Likes
Message 14 of 15

My_Civil_3D
Advocate
Advocate

thank  you this is working, i am also trying to go thru your code step by step so i can also learn from this.

Civil 3D Certified Professional
0 Likes
Message 15 of 15

My_Civil_3D
Advocate
Advocate

im always glad when you comment, you have been a great help in my learning of lisp. you are appreciated

Civil 3D Certified Professional
0 Likes