FIrst go at AutoLisp in over 20 years - Too Many Arguments

FIrst go at AutoLisp in over 20 years - Too Many Arguments

cbenner
Mentor Mentor
1,653 Views
12 Replies
Message 1 of 13

FIrst go at AutoLisp in over 20 years - Too Many Arguments

cbenner
Mentor
Mentor

Hey there,

 

This is the kind of thing that happens when you let an Inventor piping designer play with AutoLisp.  LOL

 

Would one of you who knows what they are doing please take a look at this (admittedly very crude) code, and help me see where the "too many arguments" is coming from?  For background, what I am attempting to do here, is have a dialog with several pull down lists, and have the code concatenate a string from the selections and place it on the drawing.  The dialog box is working fine, the lists are there, and... before I started adding the "strcat" section, I was able to run it and manually return the correct values from the selections using (print "setq").  So, I'm fairly certain I am capturing the variable.  I just don't seem to know how to tell it what to do with them once I have them.  Any help, and advice (so I learn how to do it right) would be greatly appreciated.

 

Thanks in Advance.

(defun C:ltag ()
  (setq	PSIZE '("1/4"  "1/2"  "3/4"  "1"    "1 1/2"	  "2"	 "3"
		"4"    "6"    "8"    "10"   "12"   "14"	  "16"	 "18"
		"20"   "24"))			
  (setq	PMAT '("PVC"	   "CPVC"      "CSBW"	   "CSSC"
	       "316BW"	   "310BW"     "304BW"	   "TIBW"
	       "TISC"	   "GALV"      "PVDFSW"	   "PVDFSC"
	       "PTFE/DI"   "ETFE/CS"   "PVC/FRP"   "CPVC/FRP"
	       "FRP"	   "HDPESW"    "316TC"	   "PVDFFS"
	       "316S"))
  (setq dcl_id (load_dialog "linetag.dcl")) 
  (if (not (new_dialog "linetag" dcl_id))
  (exit))					

  (start_list "size")			
  (mapcar 'add_list PSIZE)		
  (end_list)				

  (start_list "mat")			
  (mapcar 'add_list PMAT)		
  (end_list)				

  (setq	siz (get_tile "size"))
  (setq mat (get_tile "mat"))  

  (action_tile "cancel" "(done_dialog) (setq userclick nil)")
  (action_tile "accept"	"(strcat (siz mat))" "(done_dialog)(setq userclick T))")				
  (start_dialog)
  (unload_dialog dcl_id)		
  (princ)
)					

(princ)

 

0 Likes
Accepted solutions (3)
1,654 Views
12 Replies
Replies (12)
Message 2 of 13

rkmcswain
Mentor
Mentor
Hey @cbenner - can you attach the .DCL file too? Thanks.  Hang on, I think (strcat (siz mat) should be (strcat siz mat). Oh, and there should only be two arguments for that (action_tile) 
(action_tile "accept" "(setq ans (strcat siz mat))(done_dialog)(setq userclick T)")

I am visually guessing, no testing w/o the .DCL
R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 3 of 13

CodeDing
Advisor
Advisor
  (action_tile "cancel" "(done_dialog)X(setq userclick nil)")
  (action_tile "accept"	"(strcat (siz mat))" "(done_dialog)(setq userclick T))")				

 


@cbenner,

 

Just from a quick glance, you might need to remove the space at X

and perhaps remove a right bracket

 

Hope that helps.

 

Best,

~DD

Message 4 of 13

rkmcswain
Mentor
Mentor
Accepted solution

Try this.

Tested.

 

(defun C:ltag ()
  (setq	PSIZE '("1/4"  "1/2"  "3/4"  "1"    "1 1/2"	  "2"	 "3"
		"4"    "6"    "8"    "10"   "12"   "14"	  "16"	 "18"
		"20"   "24"))			
  (setq	PMAT '("PVC"	   "CPVC"      "CSBW"	   "CSSC"
	       "316BW"	   "310BW"     "304BW"	   "TIBW"
	       "TISC"	   "GALV"      "PVDFSW"	   "PVDFSC"
	       "PTFE/DI"   "ETFE/CS"   "PVC/FRP"   "CPVC/FRP"
	       "FRP"	   "HDPESW"    "316TC"	   "PVDFFS"
	       "316S"))
  (setq dcl_id (load_dialog "linetag.dcl")) 
  (if (not (new_dialog "linetag" dcl_id))
  (exit))					

  (start_list "size")			
  (mapcar 'add_list PSIZE)		
  (end_list)				

  (start_list "mat")			
  (mapcar 'add_list PMAT)		
  (end_list)				

  ;(setq	siz (get_tile "size"))
  ;(setq mat (get_tile "mat"))  

  (action_tile "cancel" "(done_dialog) (setq userclick nil)")
  (action_tile "accept"	"(setq res (strcat (get_tile \"size\") (get_tile \"mat\")))(done_dialog)(setq userclick T)")				
  (start_dialog)
  (unload_dialog dcl_id)		
  (princ)
)

;;;

;;; DCL CODE

linetag : dialog { label = "linetag";
: row
{
 : list_box { label = "Select items to unblank." ; key = "size" ; width = 25 ; multiple_select = false ;}
 : list_box { label = "Select items to unblank." ; key = "mat" ; width = 25 ; multiple_select = false ;}
 }
 ok_cancel;
}
R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 5 of 13

cbenner
Mentor
Mentor

@rkmcswain @CodeDing

 

First, thanks guys for responding.

 

Second,... I lied.  I am no longer getting the variable to pull the string from the list.  The dcl has an initial value set ( I copied this from some tutorial).  The variable seem to be returning only this initial value, and not getting anything from the pull downs.  I am attaching the dcl here in case you feel like helping more.

 

If I (we) can make this work, I have many applications for it in mind.  And a free beer at AU for the one who helps me get there first.  J/K, free AU beer all around (as long as it's free to me).

 

 

0 Likes
Message 6 of 13

rkmcswain
Mentor
Mentor
See post 4





R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 7 of 13

scot-65
Advisor
Advisor
Accepted solution
Calling a get_tile for lists/pops returns the integer position
within the list/pop (as a string). The position is zero (0) base.
One will have to transform the index to the list.

(setq size (nth (atoi (get_tile "size")) PSIZE))

You also need to initialize the tile otherwise nil will be
returned and code will error out.

(set_tile "size" "0")

As RK pointed out, grab the values when "accept".
I usually do this by calling/creating a sub-function "GET",
as sometimes there are just too many quotes to escape
had I tried to do this inside the action_tile statement.

(action_tile "accept" "(MyProgram_GET)(done_dialog 1)")

where:
(defun MyProgram_GET ()
(setq res (strcat
(nth (atoi (get_tile "size")) PSIZE)
(nth (atoi (get_tile "mat")) PMAT)
))
);defun

Lastly, use the integer return of done_dialog as the flag
to enter into your "main" execution code block:
(action_tile "cancel" "(done_dialog 0)")
"accept" - see above.
(setq sd (start_dialog))

then:
(if (and sd (= sd 1))
...have fun
);if

Advanced users:
Use mode_tile (=1) to turn off the accept button and re-enable
when both list boxes have one line selected (highlighted).
This method does not require the list boxes to be initialized.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 8 of 13

cbenner
Mentor
Mentor

@rkmcswain

 

Your code works, but returns the integer value of the selection from the dialog.  Love what you showed me on the lists, however... I may use that .

 

@scot-65

 

I see what you are trying to say, but it's a bit advanced for my level.  I've tried combining what you proposed with some of RK's code, and I've been in a continuous loop of debugging ever since.  Bad argument type, too few arguments, too many arguments, malformed string.....

 

I'm new to this, I'm afraid I need to be talked down to like a kindergartner.  I'm posting the latest of what I have tried, using bits and pieces of code from both of you.... made a mess of it is what I did.  I need to take what RK wrote, and get the string value of the picks from the list.  Eventually I'm going to add more lists, probably about 6 in total.... but I started small with just these two.

0 Likes
Message 9 of 13

cbenner
Mentor
Mentor
Accepted solution

I think I've got it....

 

I looked at both of your suggestions again @scot-65 & @rkmcswain, and took it a little more slowly combining them.  This is what I got, and it returns a concatenation of the string values taken from the drop downs.  Exactly what I wanted.  Phase on complete!


(defun C:ltag () (setq PSIZE '("1/4" "1/2" "3/4" "1" "1 1/2" "2" "3" "4" "6" "8" "10" "12" "14" "16" "18" "20" "24")) (setq PMAT '("PVC" "CPVC" "CSBW" "CSSC" "316BW" "310BW" "304BW" "TIBW" "TISC" "GALV" "PVDFSW" "PVDFSC" "PTFE/DI" "ETFE/CS" "PVC/FRP" "CPVC/FRP" "FRP" "HDPESW" "316TC" "PVDFFS" "316S")) (setq dcl_id (load_dialog "linetag.dcl")) (if (not (new_dialog "linetag" dcl_id)) (exit)) (start_list "size") (mapcar 'add_list PSIZE) (end_list) (start_list "mat") (mapcar 'add_list PMAT) (end_list) (set_tile "size" "0") (set_tile "mat" "0") ;(setq siz (nth (atoi (get_tile "size")) PSIZE)) ;(setq mat (nth (atoi (get_tile "mat")) PMAT)) (action_tile "cancel" "(done_dialog) (setq userclick nil)") (action_tile "accept" "(setq res (strcat (nth (atoi (get_tile \"size\")) PSIZE) (nth (atoi (get_tile \"mat\")) PMAT))) (done_dialog)(setq userclick T)") (start_dialog) (unload_dialog dcl_id) (princ) )

Thanks for your suggestions.... I may be back when I move on to phase two.

Message 10 of 13

cbenner
Mentor
Mentor

@rkmcswain

 

OK... got one for this problem?  I've done some research in the forums and online, to get the inch mark to show up on my pipe sizes.  In the list PSIZE, I am now showing the items as: "4\"" (ex).  Seems to be the consensus on how to get the inch marks to show up.  And they ARE,... except that the back slash is also going for a ride with it.  So my output is 4\", instead of just 4".

 

Any idea how to get rid of the extra character?

0 Likes
Message 11 of 13

rkmcswain
Mentor
Mentor

I'm not sure what you mean by the "slash goes along for the ride".

 

If I do this:

 

(setq a "1\"")
(alert a)

...then I get this. 

 

one.PNG

 

No slash.

 

Without knowing exactly where this is happening, I would only add the inch mark [ you could also use (chr 34) ] - when you need to print something for the user. In other words, only worry about dealing with real numbers in your calculations. 

 

Maybe I'm missing something.....

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 12 of 13

scot-65
Advisor
Advisor
(action_tile "cancel" "(done_dialog) (setq userclick nil)")

Anything beyond the done_dialog statement will not evaluate.
Swap positions or develop another geometry
[suggest employing the setq sd (start_dialog) method].

;enter MAIN and check the output
(if (and sd (= sd 1))
(alert res)
(alert "Function canceled.")
);if

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 13 of 13

cbenner
Mentor
Mentor

@scot-65 @rkmcswain @CodeDing

 

Thank you all for your help on this.  I used tips from all of you in completing this program.  Not really sure how to mark this as solved, I hate to mark my own post as a solution.  So, I'm sharing it among the best tips I got.   Here is a quick video of it in action.