Help with a block insert program with QTY

Help with a block insert program with QTY

murmanator
Advocate Advocate
854 Views
5 Replies
Message 1 of 6

Help with a block insert program with QTY

murmanator
Advocate
Advocate

Hello, in the program copied below, I am attempting to insert a dynamic block with visibility state selection AND use a quantity function to prompt for quantity of blocks to insert. The QTY function part is not working. It does the single block insert fine, when you enter anything greater than 1 it inserts 1 then bails out with "error: bad function" in the command line (see lines in RED). Im using this QTY function in other programs and it works but in those cases I have a separate program being called in the IF part. Is there some reason that I cant have that AutoRotate and visibility state call in the QTY function? Am I just doing that part wrong? Thanks for looking

 

(defun C:iTRL () (iTRL nil)) 
(DEFUN iTRL (TYP / pt)
(GV)
(PB)
(SETVAR 'CLAYER "ACCESSORIES")
(initget 1)
(IF (NULL TYP)
(PROGN (INITGET "4' 6' 8' 3' 16\" SCREEN-PANEL")
(SETQ TYP (COND ((GETKWORD
"\nSpecify Trellis [4'/6'/8'/3'/16\"/SCREEN-PANEL] <SCREEN-PANEL>: "
)
)
("SCREEN-PANEL")
)
)
)
)
(COND
; ((= TYP "4'") (AutoRotateBlock "DYN_TRELLIS" nil 1) ;;; Basic single block insert function 
; (chgdynprop (ENTLAST) "Visibility1" TYP)
; )

((= TYP "4'")
(INITGET 6) ;;;;;;; Insert with QTY, not working with qty greater than 1
(SETQ qty (GETINT "\nHow Many Trellises <1>: "))
(IF (>= qty 2)
(REPEAT qty ((AutoRotateBlock "DYN_TRELLIS" nil 1) (chgdynprop (ENTLAST) "Visibility" TYP))
)
((AutoRotateBlock "DYN_TRELLIS" nil 1) (chgdynprop (ENTLAST) "Visibility" TYP))
)
)
((= TYP "6'") (AutoRotateBlock "DYN_TRELLIS" nil 1)
(chgdynprop (ENTLAST) "Visibility1" TYP)
)
((= TYP "8'") (AutoRotateBlock "DYN_TRELLIS" nil 1)
(chgdynprop (ENTLAST) "Visibility1" TYP)
)
((= TYP "3'") (AutoRotateBlock "DYN_TRELLIS" nil 1)
(chgdynprop (ENTLAST) "Visibility1" TYP)
)
((= TYP "16\"") (AutoRotateBlock "DYN_TRELLIS" nil 1)
(chgdynprop (ENTLAST) "Visibility1" TYP)
)
((= TYP "SCREEN-PANEL")
(SETQ PNT (GETPOINT "\n\t\t =>> Pick a Location <<= "))
(if PNT
(progn
(vl-cmdf "-INSERT" "DYN_TRELLIS" PNT "" "" "" "")
(chgdynprop (entlast) "Visibility1" TYP)
)
)
(C:ESP)
)
)
(SV)
(PRINC)
)

0 Likes
Accepted solutions (2)
855 Views
5 Replies
Replies (5)
Message 2 of 6

doaiena
Collaborator
Collaborator
Accepted solution

The error is in this line:

((= typ "4'")
(initget 6) ;;;;;;; insert with qty, not working with qty greater than 1
(setq qty (getint "\nhow many trellises <1>: "))
(if (>= qty 2)
(repeat qty ((autorotateblock "dyn_trellis" nil 1) (chgdynprop (entlast) "visibility" typ))
)
((autorotateblock "dyn_trellis" nil 1) (chgdynprop (entlast) "visibility" typ))
) 
)


The error was caused by the doubled parentheses on that line.

PS:

I just noticed you have the same error inside the repeat statement. Remove the extra parentheses and the code whould work fine.

 

PS#2:
Instead of having an IF statement for the quantity check, you could set it to 1 by default, if the user input is nil and then just repeat.
Also it's good for visibility's sake to add an extra line inbetween the conditions inside the COND statement and leave the condition on its own line.

(cond

((= typ "4'")
(initget 6)
(setq qty (getint "\nhow many trellises <1>: "))
(if (not qty) (setq qty 1))
(repeat qty
(autorotateblock "dyn_trellis" nil 1)
(chgdynprop (entlast) "visibility" typ)
);repeat
)

((= typ "6'")
(autorotateblock "dyn_trellis" nil 1)
(chgdynprop (entlast) "visibility1" typ)
)

((= typ "8'")
(autorotateblock "dyn_trellis" nil 1)
(chgdynprop (entlast) "visibility1" typ)
)

((= typ "3'")
(autorotateblock "dyn_trellis" nil 1)
(chgdynprop (entlast) "visibility1" typ)
)

...

 

0 Likes
Message 3 of 6

murmanator
Advocate
Advocate

Thanks for the suggestion. I changed it to this but it broke the function:

 

((= TYP "4'")
(INITGET 6) ;;;;;;; Insert with QTY, not working
(SETQ qty (GETINT "\nHow Many Trellises <1>: "))
(IF (>= qty 2)
(REPEAT qty (AutoRotateBlock "DYN_TRELLIS" nil 1) (chgdynprop (ENTLAST) "Visibility" TYP)
)
(AutoRotateBlock "DYN_TRELLIS" nil 1) (chgdynprop (ENTLAST) "Visibility" TYP)
)
)

0 Likes
Message 4 of 6

murmanator
Advocate
Advocate

This was the answer. Remove DBL parenthesis in the Repeat part, leave them in the other side of the IF:

 

((= TYP "4'")
(INITGET 6) ;;;;;;; Insert with QTY, not working
(SETQ qty (GETINT "\nHow Many Trellises <1>: "))
(IF (>= qty 2)
(REPEAT qty (AutoRotateBlock "DYN_TRELLIS" nil 1) (chgdynprop (ENTLAST) "Visibility" TYP)
)
((AutoRotateBlock "DYN_TRELLIS" nil 1) (chgdynprop (ENTLAST) "Visibility" TYP))
)
)

0 Likes
Message 5 of 6

doaiena
Collaborator
Collaborator
Accepted solution

No. It will give an error when the quantity is 1. You need a PROGN statement in order to execue multiple functions inside an IF statement.
An IF statement with multiple functions should look like this:

(if something
(progn
do this
and this
and this
);end first PROGN

(progn
ELSE do this
and this
and this
);end second/else/ PROGN
);end IF


PS on my previous post:

Instead of :

(setq qty (getint "\nhow many trellises <1>: "))
(if (not qty) (setq qty 1))

 It should be:

(if (not (setq qty (getint "\nhow many trellises <1>: "))) (setq qty 1))
0 Likes
Message 6 of 6

murmanator
Advocate
Advocate

That did it! Thank you for all the help.

0 Likes