Help me Troubleshoot with this lisp

Help me Troubleshoot with this lisp

amrivasU38U2
Contributor Contributor
640 Views
8 Replies
Message 1 of 9

Help me Troubleshoot with this lisp

amrivasU38U2
Contributor
Contributor

Hi @paullimapa can you help me troubleshoot this lisp file.  I can't figure out the error. Running the command for the first time and selecting C2G and USB A to B works and function correctly but running the command again and hitting okay without changing the manufacturer C2G and USB A to A display an output which is supposedly for USB A to B. I noticed that running the command for the second time. Choose connector type options switches to USB A to A.

 
 
 
 
 
 
 
 
 
0 Likes
641 Views
8 Replies
Replies (8)
Message 2 of 9

paullimapa
Mentor
Mentor

paullimapa_0-1731569627694.png

The problem is caused by the fact that you have two different values you're trying to equate to the same variable. Your dcl under Choose Connector Type is using the following two keys:

"USB_A_TO_A"USB_A_TO_B"
But you want the Block attribute to use the following two corresponding values:
"USB A M TO A M" & "USB A M TO B M"
So to resolve this I decided in addition to using variable: 
connector-type
I introduced another related variable called:
connector-value
Now your do_connector_type_select function will save both of these values when either of those two keys are selected:

 

;;; do_connector_type_select 
 (defun do_connector_type_select (itm)
;   
  (setq connector-type itm) ; use this as type
;
  (cond
   ((eq itm "USB_A_TO_A") 
;    (setq connector-type "USB A M TO A M")
    (setq connector-value "USB A M TO A M") ; use this as value
   )
   ((eq itm "USB_A_TO_B") 
;    (setq connector-type "USB A M TO B M"
    (setq connector-value "USB A M TO B M") ; use this as value
   )
  )   
 )

 

Also under your do_radio_button function you need to set the previously saved global *connector-type* variable as the selected key when the dialog appears like this:

 

;;; do_radio_button
 (defun do_radio_button ()
  (if (not *usb-manu*) (setq *usb-manu* "LIBERTY"))
  (set_tile *usb-manu* "1") ; select default
  (if (not *connector-type*) (setq *connector-type* "USB_A_TO_A"))
;  (set_tile "USB_A_TO_A" "1") ; select default connector type
  (set_tile *connector-type* "1") ; select default connector type
 )

 

Lastly if the user chooses to accept the default without selecting either of these two keys the following code is used to accommodate after the OK button is selected:

 

;      (if connector-type (setq *connector-type* connector-type)) ; save connector type
      (if connector-type 
        (setq *connector-type* connector-type) ; then connector type & value are defined
        (do_connector_type_select *connector-type*) ; else define value using default type
      ) 

 

And updating the attribute value line of code is now changed to:

 

;      (setpropertyvalue (entlast) att-desc (strcat *usb-model* " " *connector-type*)) ; fill in description
      (setpropertyvalue (entlast) att-desc (strcat *usb-model* " " connector-value)) ; fill in description using value

 

see attached revised usb6.lsp


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 9

amrivasU38U2
Contributor
Contributor

Thank you so much. I just notice my cond function is not properly configured. Can you please modify the cond part so that the att-model will match the correct description.

FOR LIBERTY:

3FT USB A TO A att-model should be E-USBAA-3

6FT USB A TO A att-model should be E-USBAA-6

10FT USB A TO A att-model should be E-USBAA-10

15FT USB A TO A att-model should be E-USBAA-15

 

3FT USB A TO B att-model should be E-USBAB-3

6FT USB A TO B att-model should be E-USBAB-6

10FT USB A TO B att-model should be E-USBAB-10

15FT USB A TO B att-model should be E-USBAB-15


FOR C2G:

3.3FT USB A TO A att-model should be 54170

6.6FT USB A TO A att-model should be 54171

9.8FT USB A TO A att-model should be 54172


3.3FT USB A TO B att-model should be 54173

6.6FT USB A TO B att-model should be 54174

9.8FT USB A TO B att-model should be 54175

 

 

 

 
 
0 Likes
Message 4 of 9

ec-cad
Collaborator
Collaborator

Lot of copy/paste, but here's the function revised.

;;; do_connector_type_select 
 (defun do_connector_type_select (itm)
  (setq connector-type itm) ; use this as type
  (cond

; don't know if you still want the next 2 types, if not, delete those..
   ((eq itm "USB_A_TO_A") 
    (setq connector-value "USB A M TO A M") ; use this as value
   )
   ((eq itm "USB_A_TO_B") 
    (setq connector-value "USB A M TO B M") ; use this as value
   )

; FOR LIBERTY
; 3FT USB A TO A att-model should be E-USBAA-3
; 6FT USB A TO A att-model should be E-USBAA-6
; 10FT USB A TO A att-model should be E-USBAA-10
; 15FT USB A TO A att-model should be E-USBAA-15
; 3FT USB A TO B att-model should be E-USBAB-3
; 6FT USB A TO B att-model should be E-USBAB-6
; 10FT USB A TO B att-model should be E-USBAB-10
; 15FT USB A TO B att-model should be E-USBAB-15

   ((eq itm "3FT USB A TO A") 
    (setq connector-value "E-USBAA-3") ; use this as value
   )
   ((eq itm "6FT USB A TO A") 
    (setq connector-value "E-USBAA-6") ; use this as value
   )
   ((eq itm "10FT USB A TO A") 
    (setq connector-value "E-USBAA-10") ; use this as value
   )
   ((eq itm "15FT USB A TO A") 
    (setq connector-value "E-USBAA-15") ; use this as value
   )
   ((eq itm "3FT USB A TO B") 
    (setq connector-value "E-USBAB-3") ; use this as value
   )
   ((eq itm "6FT USB A TO B") 
    (setq connector-value "E-USBAB-6") ; use this as value
   )
   ((eq itm "10FT USB A TO B") 
    (setq connector-value "E-USBAB-10") ; use this as value
   )
   ((eq itm "15FT USB A TO B") 
    (setq connector-value "E-USBAB-15") ; use this as value
   )

;FOR C2G:
; 3.3FT USB A TO A att-model should be 54170
; 6.6FT USB A TO A att-model should be 54171
; 9.8FT USB A TO A att-model should be 54172
; 3.3FT USB A TO B att-model should be 54173
; 6.6FT USB A TO B att-model should be 54174
; 9.8FT USB A TO B att-model should be 54175
   ((eq itm "3.3FT USB A TO A") 
    (setq connector-value "54170") ; use this as value
   )
   ((eq itm "6.6FT USB A TO A") 
    (setq connector-value "54171") ; use this as value
   )
   ((eq itm "9.8FT USB A TO A") 
    (setq connector-value "54172") ; use this as value
   )
   ((eq itm "3.3FT USB A TO B") 
    (setq connector-value "54173") ; use this as value
   )
   ((eq itm "6.6FT USB A TO B") 
    (setq connector-value "54174") ; use this as value
   )
   ((eq itm "9.8FT USB A TO B") 
    (setq connector-value "54175") ; use this as value
   )
;
  ); cond   
 )

 

ECCAD

 

0 Likes
Message 5 of 9

Sea-Haven
Mentor
Mentor

@ec-cad there appears to be patterns in the strings could these patterns be used in stead of Cond ?

 

"3FT USB A TO A”
"E-USBAA-3"
(setq c1 (substr str 1 1 ))
(setq c2 (substr str (strlen str)))
(setq str (strcat "E-USBA" c1 "-" c2))

 

0 Likes
Message 6 of 9

paullimapa
Mentor
Mentor

if you recall from another thread @amrivasU38U2 prefers to see everything spelled out:

"I find it more easier to tweak and add another manufacturer and cable length."

 


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

Sea-Haven
Mentor
Mentor

You are right when learning the longer way can be the simplest.

0 Likes
Message 8 of 9

paullimapa
Mentor
Mentor

Although as a coder like you I prefer the shortcut...lol


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

amrivasU38U2
Contributor
Contributor

Hello everyone. I prefer to see everything, so it is easier for me to add different cable length since there are instances that the new cable model will not follow the same pattern. Also, since I have not enough knowledge on this, it is much easier to understand if the code is not that complicated. 

 
0 Likes