help with an output

help with an output

Anonymous
Not applicable
382 Views
5 Replies
Message 1 of 6

help with an output

Anonymous
Not applicable

Hello all,

 

I am editting someone else's code and trying to break it down and simplify it, however I am stuck trying to figure out what some parts of the code do.

 

I've added notes in all the parts I can figure out, but there are a few parts that don't really make sense to me and are not putting out the results I'm expecting.  

 

what the code does is when you select a block in CAD, it will read the dynamic properties and label it and give it a capacity rating according to your input or the list provided.  

 

originally, it would also run a calculation to get it's vertical forces depending what angle the block was at, but I am removing that portion.  part of this exercise is also to clean up the code a bit as it tends to crash unexpectedly every so often.

 

here is the code:

(defun polyslingratingcheck (/ test
			     polysling
			     slinglength
			     userdatalabel
			     sset
			     sset1
			     )
    (if (not userdata) ;;if userdata has been previously set in this session, it is set to blank or ""
    (setq userdata "")
  )

;;this portion grabs the length of the poly sling via block properties and asks for the size/capacity and stores it to userdatalabel
  (setq	test T 
	polytext ""
	polysling nil
	slinglength
	 (getdynpropvalue
	   (vlax-ename->vla-object name)
	   "Sling Length"
	 )
	userdatalabel
	 (getstring
	   (strcat
	     "Enter polyround size designation or capacity in KIP(__K) <" userdata ">: "
	   )
	 )
  )

;;if one of the below is typed in, it will use the far right numbers for a capacity
  (if (= userdatalabel "")
    (setq userdata userdata)
    (setq userdata  userdatalabel)
  )
  (while test
    (setq polyslingcap
	   (cond ((wcmatch (strcase userdata) "A3") 3000)
		 ((wcmatch (strcase userdata) "A6") 6000)
		 ((wcmatch (strcase userdata) "A9") 9000)
		 ((wcmatch (strcase userdata) "A12") 12000)
		 ((wcmatch (strcase userdata) "A14") 14000)
		 ((wcmatch (strcase userdata) "A17") 17000)
		 ((wcmatch (strcase userdata) "A23") 23000)
		 ((wcmatch (strcase userdata) "A26") 26000)
		 ((wcmatch (strcase userdata) "A32") 32000)
		 ((wcmatch (strcase userdata) "A40") 40000)
		 ((wcmatch (strcase userdata) "A54") 54000)
		 ((wcmatch (strcase userdata) "A68") 68000)
		 ((wcmatch (strcase userdata) "A70") 70000)
		 ((wcmatch (strcase userdata) "A90") 90000)
		 ((wcmatch (strcase userdata) "LL1") 2600)
		 ((wcmatch (strcase userdata) "LL2") 5300)
		 ((wcmatch (strcase userdata) "LL3") 8400)
		 ((wcmatch (strcase userdata) "LL4") 10600)
		 ((wcmatch (strcase userdata) "LL5") 13200)
		 ((wcmatch (strcase userdata) "LL6") 16800)
		 ((wcmatch (strcase userdata) "LL7") 21200)
		 ((wcmatch (strcase userdata) "LL8") 25000)
		 ((wcmatch (strcase userdata) "LL9") 31000)
		 ((wcmatch (strcase userdata) "LL10") 40000)
		 ((wcmatch (strcase userdata) "LL11") 53000)
		 ((wcmatch (strcase userdata) "LL12") 66000)
		 ((wcmatch (strcase userdata) "LL13") 90000)
		 ((/= (atof userdata) 0) (atof userdata))
		 (nil)
	   )
    )

;;i don't know what this portion is for, but it is seems to be required for the code to work
    (if	polyslingcap
      (setq polysling
	     (cond ((<= 90000 polyslingcap)
		    (list polyslingcap 5.22 7.38 polyslingcap 7000)
		   )
		   ((> 5300 polyslingcap)
		    (list polyslingcap 0.97 1.37 polyslingcap 7000)
		   )
		   ((> 8400 polyslingcap)
		    (list polyslingcap 1.29 1.82 polyslingcap 7000)
		   )
		   ((> 10600 polyslingcap)
		    (list polyslingcap 1.66 2.34 polyslingcap 7000)
		   )
		   ((> 13200 polyslingcap)
		    (list polyslingcap 1.78 2.52 polyslingcap 7000)
		   )
		   ((> 16800 polyslingcap)
		    (list polyslingcap 2.00 2.80 polyslingcap 7000)
		   )
		   ((> 21200 polyslingcap)
		    (list polyslingcap 2.13 3.00 polyslingcap 7000)
		   )
		   ((> 25000 polyslingcap)
		    (list polyslingcap 2.62 3.71 polyslingcap 7000)
		   )
		   ((> 31000 polyslingcap)
		    (list polyslingcap 2.85 4.00 polyslingcap 7000)
		   )
		   ((> 40000 polyslingcap)
		    (list polyslingcap 3.15 4.45 polyslingcap 7000)
		   )
		   ((> 53000 polyslingcap)
		    (list polyslingcap 3.57 5.06 polyslingcap 7000)
		   )
		   ((> 66000 polyslingcap)
		    (list polyslingcap 4.00 5.62 polyslingcap 7000)
		   )
		   ((> 90000 polyslingcap)
		    (list polyslingcap 4.60 6.50 polyslingcap 7000)
		   )
	     )
      )
    )
    (if	polysling
      (setq test nil)
      (setq userdatalabel
	     (getstring
	       (strcat
		 "Polysling not supported. Enter polyround size designation or capacity in KIP(__K) <" userdata ">: "
	       )
	     )
      )
    )
    (if	(= userdatalabel "")
      (setq userdata userdata)
      (setq userdata userdatalabel)
    )
  )


  ;;Poly Round sling labels that are entered in the leader
  (setq
    sltext (strcat "POLYESTER ROUND SLING, " (strcase userdatalabel) " x " (rtos (/ slinglength 25.4) 4)
		   "\n"
		   (rtos (/ (float (nth 0 polysling)) cvtonne2lb) 2 1)
		   " Te ("
		   (flakenum (rtos (nth 0 polysling) 2 0))
		   " lbs) CAP"
	   )
  )

)

 

 

thanks

 

0 Likes
383 Views
5 Replies
Replies (5)
Message 2 of 6

paullimapa
Mentor
Mentor

Try making the following changes and you would no longer need the unknown lines of the code:

Replace the following 2 lines towards the end of the code:

(rtos (/ (float (nth 0 polysling)) cvtonne2lb) 2 1)
(flakenum (rtos (nth 0 polysling) 2 0))

 

with these two lines:

(rtos (/ (float polyslingcap) cvtonne2lb) 2 1)
(flakenum (rtos polyslingcap 2 0))

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store


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

hmsilva
Mentor
Mentor

in addition to Paul Li advices,
the code expects an ename as argument (defun polyslingratingcheck ( name / test polysling ....
And the variabble 'cvtonne2lb' comes from? It's a global one?

 

Henrique

EESignature

0 Likes
Message 4 of 6

Anonymous
Not applicable

PLI: unfortunately, it still asks for an input even with that change (I do see what it is you were doing there though).  it seems to be expecting something from the unknown area.  I cant figure out what the list he created is used for, the 2 random numbers have no familiarity to me.  7000 is the maximum psi allowable.

 

hmsilva: its a global variable that converts tonnes to lbs.  that part of the code is working fine.  

0 Likes
Message 5 of 6

paullimapa
Mentor
Mentor

O, there's still this portion of the code that's asking to test polysling.  So replace these lines of code:

    (if polysling
      (setq test nil)
      (setq userdatalabel
         (getstring
           (strcat
         "Polysling not supported. Enter polyround size designation or capacity in KIP(__K) <" userdata ">: "
           )
         )
      )
    )

 

with this:

(setq test nil)

 

Also since I don't have the dynamic block that you are using, I really cannot fully test out the code as to what else it's asking for.

 

 

Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
Exchange App Store

 


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

Anonymous
Not applicable

thanks PLI!!

 

that worked as expected.

I did find another way around it late last night, but it was probably redundant the way I did it.

 

the last problem I'm having is, if I label something with LL13, LL13 becomes the default if I hit space bar.  it should in theory insert LL13 in the text at the end, but it doesn't. it just enters a blank.  but if I type LL13 it acts as expected.  I'm thinking i'm missing a a function to set userdata to userdatalabel somewhere.

 

edit: figured it out.  I aded this after the test

 

(if (/= (atof userdata) 0)
(setq userdatalabel (strcat (flakenum userdata) " lbs"))
(setq userdatalabel userdata)
)

 

 

 

I also changed 

 

  (if (= userdatalabel "")
    (setq userdata userdata)
    (setq userdata  userdatalabel)

to this since it made more sense to me.

  (if (/= userdatalabel "")
    (setq userdata userdatalabel)

.

 

this is now the code I'm using.  

 

(defun polyslingratingcheck (/ test
			     polysling
			     slinglength
			     userdatalabel
			     sset
			     sset1

			     )

    (if (not userdata)
    (setq userdata "")
  )
  (setq	test T 
	polytext ""
	polysling nil
	;ang (abs ang)
	slinglength
	 (getdynpropvalue
	   (vlax-ename->vla-object name)
	   "Sling Length"
	 )
	userdatalabel
	 (getstring
	   (strcat
	     "Enter polyround size designation or capacity in KIP(__K) <" userdata ">: "
	   )
	 )
  )
  (if (/= userdatalabel "")
    (setq userdata userdatalabel)
  )
  (while test
    (setq polyslingcap
	   (cond ((wcmatch (strcase userdata) "A3") 3000)
		 ((wcmatch (strcase userdata) "A6") 6000)
		 ((wcmatch (strcase userdata) "A9") 9000)
		 ((wcmatch (strcase userdata) "A12") 12000)
		 ((wcmatch (strcase userdata) "A14") 14000)
		 ((wcmatch (strcase userdata) "A17") 17000)
		 ((wcmatch (strcase userdata) "A23") 23000)
		 ((wcmatch (strcase userdata) "A26") 26000)
		 ((wcmatch (strcase userdata) "A32") 32000)
		 ((wcmatch (strcase userdata) "A40") 40000)
		 ((wcmatch (strcase userdata) "A54") 54000)
		 ((wcmatch (strcase userdata) "A68") 68000)
		 ((wcmatch (strcase userdata) "A70") 70000)
		 ((wcmatch (strcase userdata) "A90") 90000)
		 ((wcmatch (strcase userdata) "LL1") 2600)
		 ((wcmatch (strcase userdata) "LL2") 5300)
		 ((wcmatch (strcase userdata) "LL3") 8400)
		 ((wcmatch (strcase userdata) "LL4") 10600)
		 ((wcmatch (strcase userdata) "LL5") 13200)
		 ((wcmatch (strcase userdata) "LL6") 16800)
		 ((wcmatch (strcase userdata) "LL7") 21200)
		 ((wcmatch (strcase userdata) "LL8") 25000)
		 ((wcmatch (strcase userdata) "LL9") 31000)
		 ((wcmatch (strcase userdata) "LL10") 40000)
		 ((wcmatch (strcase userdata) "LL11") 53000)
		 ((wcmatch (strcase userdata) "LL12") 66000)
		 ((wcmatch (strcase userdata) "LL13") 90000)
		 ((/= (atof userdata) 0) (atof userdata))
		 (nil)
	   )
    )


    (setq test nil)


    (if	(/= userdatalabel "")
      (setq userdata userdatalabel)
    )
  )


  ;;Poly Round sling labels
  (setq
    sltext (strcat "POLYESTER ROUND SLING, " (strcase userdatalabel) " x " (rtos (/ slinglength 25.4) 4)
		   "\n"
		   (rtos (/ (float polyslingcap) cvtonne2lb) 2 1)
		   " Te ("
		   (flakenum (rtos polyslingcap 2 0))
		   " lbs) CAP\n"
		   "("(rtos quantity 2 0) " REQ'D)"
	   )
  )

 

0 Likes