Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP Character limitations

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
blamAU
1013 Views, 13 Replies

LISP Character limitations

hello everyone,

 

I was hoping you could help me solve a little problem.

 

I have a LISP routine that pulls information from a dynamic block then throws it in a leader and labels the block for you.

 

everything worked wonderfully, until our block names in our library changed.  they went from 4-6 character names(MP24HD) to 31+ characters (SPREADER-BAR P042SPR-MP24-HD FV).  unfortunately, I cannot strip the block names down any to anything less and most will be even longer what we have now.

 

I end up getting this error:  "; error: bad argument type: VLA-OBJECT nil"

 

is there any work around for this?

 

I've attached the lisp for reference but there is quite a bit in there.  the call outs are at the bottom of the routine.  it was developed by someone else thats no longer around to help.

 

any help would be much appreciated.

 

thanks

13 REPLIES 13
Message 2 of 14
dbroad
in reply to: blamAU

This is not an answer to your problem but (hopefully) some helpful suggestions.

 

You have posted a 160KB lisp program with not a single comment in the file hoping that someone else will debug the mess you've made.

 

1) Add comments to your code.  No one can maintain or interpret large programs without comments.

2) Consolidate your code so you're not doing the same things over and over.  Example:  In the last page or 2 of your code, you have the following at least 20 times:  (STRCASE (VLAX-GET (VLAX-ENAME->VLA-OBJECT name) 'effectivename))

 

Why not store the value once and then use it?

 

3)You seem to have an overreliance on wcmatch as a lookup tool but are using it in a repetitive way.  It has the capability to lookup more than one pattern at a time.  Instead of (if (and (not(wcmatch...)(not(wcmatch ...)(not(wcmatch...)) just put all the patterns in one check.

 

4)You check things that don't need checking.  Right after you declare a variable local (meaning it has no value at the beginning of the routine, you check to see if it has a value before setting it.

 

These are just a few things I see when scanning the end of your file.  Clean up your code in these ways and perhaps you can begin to debug it yourself.

 

If you want more input, post a drawing file that contains examples of the items you wish to process.

Architect, Registered NC, VA, SC, & GA.
Message 3 of 14
paullimapa
in reply to: dbroad

according to OP:
"it was developed by someone else thats no longer around to help."

Area Object Link | Dwg Setup | Feet-Inch Calculator | List on Steroids
Exchange App Store


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 14
blamAU
in reply to: dbroad

Hi dbroad,

 

unfortunately, I am not a coder.  I only know very basic lisp.

 

I dont know how much of the code works, only small portions of it.

 

as pli mentioned, I did not create this code.  I've just been trying to figure out how it works and how to make it work better.

Message 5 of 14
Kent1Cooper
in reply to: blamAU


@blamAU wrote:

.... 

I end up getting this error:  "; error: bad argument type: VLA-OBJECT nil"

....


That means something that wants a VLA Object to work with is being fed nil instead.  Working backward from the end, it seems that a lot of things are turning the 'name' variable into a VLA object, and looking for various properties from that.  If 'name' didn't have an entity name stored in it, that conversion to a VLA object would return nil, and the things looking for properties from it would return just that kind of error message.

 

This is a place where the problem might possibly lie:
....

(setq entpick (entsel "\nSelect leader text or rigging block:") name (car entpick))

....

 

If the User misses in picking that [or if that was Mtext, in picking the Block that it then asks them to select, replacing the 'name' variable], then the 'entpick' variable would be nil, and therefore so would the 'name' variable, which would cause that problem.  However, if that's the case, there ought also to be an

 

; error: bad argument type: lentityp nil

 

message, from the attempt to convert 'name' [with nothing in it] to a VLA object.  Is there such a message?

 

I do get a little confused by the fact that the variable 'name' is used for an entity name in most places, but for a text string in others -- I didn't dig deeply enough to figure all of that out.

Kent Cooper, AIA
Message 6 of 14
Lee_Mac
in reply to: blamAU

I would suggest following the first section (Where did the Code Fail) of my tutorial Debugging Code with the Visual LISP IDE - this procedure will indicate the expression at which the code fails.

 

Lee

Message 7 of 14
blamAU
in reply to: Lee_Mac

Lee_Mac, thank you, I will have a look at trying that 

 

Kent1Copper - oddly the error i posted is the only one I get.  If i change the name of the block to anything shorter everything works again with no problem.  it seems 30 characters is the limit for this particular code for whatever reason.

 

I will shorten the code to the single one item that is causing me greif and post it with a CAD example this afternoon.

 

thank-you everyone for your help (and patience)

 

it may boil down to me sitting down and trying to learn how to re-code the entire thing and taking dbroad's advice and shortening it up to kill off any unneceasry coding.

Message 8 of 14
hgasty1001
in reply to: blamAU

Hi,

 

There used to be a limit of 31 characters for layers and block names, beginning with Autocad 2000 this changed to a 255 characters limit, but it can be limited with system  variable EXTNAMES, if 0 Autocad use the old limit, if 1 then 255 it's the limit. May be you have EXTNAMES =0 and some part of the code it's honoring this setting (just a guess).

Try posting a drawing and the procedure to reproduce the error.

 

Gaston Nunez

Message 9 of 14
dbroad
in reply to: blamAU

Sorry,

I missed the mention of another coder.  Anyway the rest of my comments are valid.  Code is easier to maintain, especially for casual coders when well commented.  I took just the last section of the code and applied my suggestions. Hopefully I didn't break anything.  Couldn't test without an example drawing.

 

(vl-load-com)
(defun c:dimrig	 (/ quantity entpick ename ang userdatalabel spreaderloadm spreaderloadi slinglength slingdia sltext pt	textname einfo obj effname oname)
  (setq quantity 2)
  (if (or (not cvtonne2lb) (= cvtonne2lb 0))
    (setq cvtonne2lb 2205.0)
    )
  (setq	entpick	(entsel "\nSelect leader text or rigging block:")
	ename	(car entpick)
	einfo	(entget ename)
	obj	(vlax-ename->vla-object ename)
	)
  (if (= (cdr (assoc 0 einfo)) "MTEXT")
    (progn (riglistquantity)
	   (setq textname ename
		 entpick  (entsel "\nPick rigging block to collect leader data:")
		 ename	  (car entpick)
		 )))
  (setq	obj   (vlax-ename->vla-object ename)
	oname (vla-get-objectname obj)
	)

  (while
    (not
      (and obj
	   (= oname "AcDbBlockReference")
	   (wcmatch (strcase (vla-get-effectivename obj))
		    "*TURNBUCKLE*,*WIREROPE*,*SLING*,*SPREADER*,*MP8&10*,*MP24LD*,*SPREADER-BAR P042SPR-MP24-HD FV*,*SHACKLE*")))
     (setq entpick (entsel "\nTry again.  Select rigging block.")
	   ename   (car entpick)
	   obj	   (vlax-ename->vla-object ename)
	   ))
  (setq effname (strcase (vla-get-effectivename obj)))
  (if
    (and (not textname)
	 (wcmatch
	   effname
	   "*SPREADER*,*MP8&10*,*MP24LD*,*SPREADER-BAR P042SPR-MP24-HD FV*"
	   ))

     (setq quantity 1)
     )
  (if (not textname)
    (setq quantity (getreal (strcat "\nItem quantity (default "
				    (rtos quantity 2 0)
				    "): "
				    ))))
  (if (not quantity)
    (if	(wcmatch
	  effname
	  "*SPREADER*,*MP8&10*,*MP24LD*,*SPREADER-BAR P042SPR-MP24-HD FV*"
	  )

      (setq quantity 1)
      (setq quantity 2)
      )
    )
  (if
    (wcmatch  effname  "*TURNBUCKLE*" )
     (setq sltext
	    (strcat
	      "2 1/2\" JAW & JAW TURNBUCKLE\n27.2Te (60,000lbs) CAP\n("
	      (rtos quantity 2 0)
	      " REQ'D)"
	      )))
  (if
    (wcmatch effname "*WIREROPE*")
     (progn (setq ang
		   (atof
		     (rtos (* (cdr (assoc 50 (entget ename))) 57.2957795131)
			   2
			   0
			   )))
	    (while (> ang 90) (setq ang (abs (- 180 ang))))
	    (setq ang	      (abs ang)
		  slinglength (getdynpropvalue obj "Sling Length")
		  slingdia    (getdynpropvalue obj "Sling Diameter")
		  sltext      (NEWRATING (/ slinglength 304.8) slingdia ang)
		  )
	    )
     )
  (if
    (wcmatch effname "*SHACKLE*")
     (setq sltext  ;;sltext is a text string here
	    (strcat
	      (vl-string-trim
		"Te (Side)"
		(vl-string-trim
		  "Te (Front)"
		  (substr (cdar (getdynprops obj)) 7)
		  )
		)
	      " Te"
	      (if (wcmatch
		    (cdar (getdynprops obj))
		    "G2160*"
		    )
		(princ " WIDE BODY ")
		(princ " ")
		)
	      "SHACKLE\n("
	      (rtos quantity 2 0)
	      " REQ'D)"
	      )
	   )
     )
  (if
    (wcmatch effname "*SPREADER*")
     (spreadertext)
     )
  (if
    (wcmatch effname "*MP8&10*")
     (mp8&10text)
     )
  (if
    (wcmatch effname "*MP24LD*")
     (mp24ldtext)
     )
  (if
    (wcmatch effname "*SPREADER-BAR P042SPR-MP24-HD FV*")
     (mp24hdtext)
     )
  (if
    (wcmatch effname "*SLING*")
     (polyslingratingcheck)
     )
  (setq dimriglayerlist (dimriglayername))
  (setq dimriglayer (getvar "clayer"))
  (if (member (list "04-DIMENSION") dimriglayerlist)
    (setvar "clayer" "04-DIMENSION")
    )
  (if sltext
    (if	textname
      (progn (setq einfo (entget textname)
einfo (subst (cons 1 sltext) (assoc 1 einfo) einfo))
(entmod einfo)
) (progn (while (not pt) (setq pt (getpoint "\nSelect location for leader text")) ) (command "leader" (cadr entpick) pt "" sltext "") (setvar "clayer" dimriglayer) ) ) ) (princ) )

 Open you program in vlide.  Choose "Break on Error" and load it from vlide.  Then run it and when it errors out, hit CTRL+F9 to see where the error occurred.

Architect, Registered NC, VA, SC, & GA.
Message 10 of 14
blamAU
in reply to: dbroad

alright,

 

I've attached a CAD file of the item that doesnt work.  as well as one that does work (with a shorter name)

 

dbroad, when I run your code, I get a different error.

 

Item quantity (default 1):  ; error: bad argument type: lentityp nil

 

when I try the debug to last break, nothing gets highlighted for some reason.

 

Gasty1001 - very good advice, I did not know that.  however that variable is indeed set to 1.

Message 11 of 14
hgasty1001
in reply to: blamAU

Hi,

 

Try the modified dimrig attached.

 

Gaston Nunez

Message 12 of 14
blamAU
in reply to: hgasty1001

gasty!!!!! you are amazing.  thank you so much.

 

I had a look at your code, and it looks quite different.  was there something in particular that you had changed specifically?

Message 13 of 14
hgasty1001
in reply to: blamAU

Hi,

 

Glad to help. Actually I changed just a few lines, and the the function definition of getdynpropvalue as the original was programed in a convoluted way, so I changed the definition to use this: LM:GetDynPropValue as it's rock solid, but i keep the name of the original just for editing speed (but referenced in code comment). Also I changed spreadertext function to receive an entity name (the name argument) as was using a local value without meaning, and changed the name of the length parameter at line 749 for the real name of the parameter in the dynamic block definition :"Spreaderbar Length (mm)".

 

As a comment this program, dimrig, was poorly developed or programed in a rush , as should require a lot of modifications, there are infinite calls to :(vlax-ename->vla-object name) where should be just one, and many others structural and functional issues. But if it works keep it.

 

Gaston Nunez

 

 

Message 14 of 14
blamAU
in reply to: hgasty1001

thank you very much.

 

I'm going to sit down and spend some time disecting this program and cleaning it up (hopefully I don't break it)

 

I believe the original author of this program was not a programmer either and learned how to write LISP on the fly.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost