Creating a Field for a Lisp variable

honkinberry
Advocate
Advocate

Creating a Field for a Lisp variable

honkinberry
Advocate
Advocate

I have been having incredible difficulty creating a Field for a Lisp variable.  Is this even actually possible?

Here's a simple example, in a fresh CAD session, create a piece of Mtext, and then fire this:

(setq v (vlax-ename->vla-object (entlast))
	
	_var001 "SAMPLE"

	c "%<\\AcVar.17.0 Lisp._var001>%"
) ; setq
(vlax-put-property v (quote TextString) c)

When I do that, I get just the #### in the Mtext.

If I double-click the field to bring up the dialog and click OK, then it displays.

 

But then the next issue - more often than not when I try to bring up the Field dialog for Lisp Variables, AutoCAD summarily crashes.  Like poof crashes, just completely goes away.  I do have about 7MB of custom Lisp code loaded, without with it doesn't crash.  Only mention that as it makes it more challenging to test.

 

But the primary issue, is that I can't seem to programmatically create a Field object scoped to a Lisp variable, unless the Field dialog has been opened to the Lisp variable section.  Which seems like a ridiculous requirement.

Any ideas out there?

 

--J

0 Likes
Reply
Accepted solutions (1)
3,041 Views
7 Replies
Replies (7)

dlanorh
Advisor
Advisor

Works OK for me. I didn't get the "####". It just replaced the existing dummy textstring ("?") with the value, although I used

 

 

(vlax-put-property v 'textstring c)

 

 

 It did error when I tried a second time, i.e. replacing a field with a field. But work if I separated the two by replacing the first field with dummy text then the text with a second field

 

Edit: Two other points:

 

1. I forgot. I use "%<\\AcVar Lisp._var001>%" so it isn't tied to any ACAD version.

2. What happens when the variable falls out of scope. i.e. for a local variable the lisp ends or for a global autocad ends?

I am not one of the robots you're looking for

0 Likes

honkinberry
Advocate
Advocate

I can get it to occasionally work.  But it is not consistent.

After restarting, it will maybe work once.  Then restart CAD, and it's #### again.

I see exceptionally few examples of assigning Lisp variables to field objects, which leads me to believe that others have hit this same hurdle.

What is your version of CAD, and does this consistently work for you every time you restart CAD?

 

--J

0 Likes

honkinberry
Advocate
Advocate

Ah!  I'm on to something.

 

In a completely fresh CAD session (please just restart Windows, and open CAD to a completely blank drawing), I cannot add a Field to Mtext, of either Lisp Variable or Custom Drawing Property.  Always ####.

Using this:

; FIRST, manually create a piece of Mtext, then:

(setq v (vlax-ename->vla-object (entlast))
	_var001 "SAMPLE"
	c "%<\\AcVar.17.0 Lisp._var001>%"
) ; setq
(vlax-put-property v (quote TextString) c)

But then type FIELD to bring up the dialog box, and click Cancel.

Note, that original piece of Mtext cannot be fixed, so re-firing the above code now renders it to "----".

 

*BUT*, if you create a NEW piece of Mtext, it works fine.  In fact, this entire *session* of CAD is fine, this drawing can be closed, a new one created, repeat the above process, and it works!  But quit the CAD session completely and try again, same issue.

 

SO, what I need, what it seems ANY programmer needs, for the Lisp Variable feature to work for Fields, is some ability to fire whatever requery event occurs when the Dialog box opens.  Obviously only a *programmer* would be associating a Lisp variable with a Field, and would likely be doing it programmatically, not via the interface.  So can I get some recognition that this is a BUG, and hopefully some tips?

 

--J

0 Likes

dlanorh
Advisor
Advisor

I'm using 2012.

 

THIS may help

I am not one of the robots you're looking for

0 Likes

honkinberry
Advocate
Advocate
Accepted solution

That post is not exactly relevant, however, the mention of the UPDATEFIELD command turns out to be the solution!

Go figure!

Thank you.  Hey, you've earned it, you can go ahead and upgrade your CAD now.  😉

 

--J

0 Likes

mark.bollons
Community Visitor
Community Visitor

Just to add that AutoCAD LT now has AutoLISP but vla- vlax- and vlr- have been excluded so this solution is not available to us poors. 

0 Likes

a_klaverQHB9B
Explorer
Explorer

I am a noob, but just tested the vla vlax... seems like it works.

Command: (setq ent(car(entsel)))
Select object: <Entity name: 17b2222f9e0>
Command: (setq vlaEnt(vlax-ename->vla-object ent))
#<VLA-OBJECT IAcadTable 0000017b493950a8>
Command: (vlax-dump-object vlaEnt t)
; IAcadTable: IAcadTable Interface
; Property values:
; AllowManualHeights = 0
; AllowManualPositions = 0

etc. etc.

 

EDIT: This should be a reply to mark.bollons ...

0 Likes