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

Area Lisp Routine not working in AutoCAD 2010 or 2011.

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
ChuckB
3520 Views, 11 Replies

Area Lisp Routine not working in AutoCAD 2010 or 2011.

Hello,

 

Can anyone help me figure out what is going wrong with the below routine.  It was working fine up in AutoCAD 2006 and 2008 but no longer functions properly in 2010 or 2011. It is supposed to label a polyline with a field linked to the polyline's area.

 

In AutoCAD 2010 and 2011 it seems to go through it's paces but the resulting field is not linked to the objects area, (it just has the #### pound signs). You can go in and relink it manually to the object area.  I think something is going wrong with the process of selecting the object and specifying the object ID. Because the object ID that the routine puts in the field expression is radically different than the Object ID that appears in the expression after you manually link it. 

 

Any help would be greatly, greatly appreciated!

 

Thanks,

 

Chuck

 

LISP:

 

(defun c:PLAREA ()
(vl-load-com)
;;get a reference to model space
(setvar "textsize" 9)
(setvar "luprec" 0)
(setq *model-space*
       (vla-get-ModelSpace
  (vla-get-ActiveDocument (vlax-get-acad-object))
       )
)
;;pass this function an entity and a point
(defun LinkedArea (ent pt / obj objID ip width str)
  ;;convert the entity to an object
  (setq obj   (vlax-ename->vla-object ent)
 ;;get the object ID
 objID (vla-get-objectid obj)
 ;;convert the point
 ip    (vlax-3D-Point pt)
 ;;set the width for the MTEXT
 width 0.0
 ;;set the string - this creates the field
 str   (strcat
  "%<\\AcObjProp Object(%<\\_ObjId "(rtos objID 2 0)">%).Area \\f \"%lu2%ct4%qf1 SF\">%"
       )
  )
  ;;Create the MTEXT entity containing the field.
  (vla-addMText *model-space* ip width str)
)

;; Set A = the entity and set B = Point for text
(setq a (car (entsel)) b (getpoint "\n Select Point: "))
;;Call the function
(linkedarea a b)
(princ)
  )

11 REPLIES 11
Message 2 of 12
SomeBuddy
in reply to: ChuckB

Works perfect here, AutoCAD 2010 English and and AutoCAD 2011 French!

Message 3 of 12
ChuckB
in reply to: SomeBuddy

REALLY!?  Weird.  I can't get it to work on any machine. I wonder if our install is missing something. Is anyone using AutoCAD 2010 or 2011from the Revit Arch Suite?  If so, would you mind verifying whether or not it works for you?

Message 4 of 12
SomeBuddy
in reply to: ChuckB

None of the specified Autocad application was installed from a Revit suite, be it Structure or Architecture. They are both standalone installs, on two different machines.

Message 5 of 12
ChuckB
in reply to: SomeBuddy

Thanks.  I wouldn't think it would matter, but you never know.

Message 6 of 12
jporter
in reply to: SomeBuddy

It doesn't work for me in ACAD 2010 or 2011. 

 

SomeBuddy, this is just a shot in the dark. . .

1.  Is your ACAD 32-bit or 64-bit?  I'm running on 64-bit.  I'm using straight vanilla CAD, not a vertical version.

2.  What OS are you using?  I'm using Windows 7. 

3.  Did you do anything to modify the code?  I copied the code into a text editor and saved it as PLAREA.lsp.  (I've attached it for you to view).  Do me a favor, download it, run it, and please tell me your results.

 

I know none of this should matter with such a basic code, but I'm just trying to find anything that might be causing the issue. 

 

Jason Porter
ASTI Civil Solutions Technical Advisor
www.asti.com
Message 7 of 12
RKLindner
in reply to: ChuckB

;;; 2010 example of new format of field
%<\AcObjProp Object(%<\_ObjId 8796088857920>%).Area \f "%lu2%ct4%qf1 SQ. FT.">%

;;; from research on Autodesk site for 64bit autocad..
(vlax-invoke-method (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))) "GetObjectIdString" (vlax-ename->vla-object (car (nentsel))) :vlax-False)

 I have pasted the info I found when my area routine stopped working when we switched to 64bit Autocad 2010.  As you will notice, the formating of the fields have changed as well as how entity selection gets handled.  Adjust accordingly to fit your needs.  You will need to alter your routine and substitute the above.

 

Richard

Message 8 of 12
SomeBuddy
in reply to: jporter

Vanilla AutoCAD for both of them, on Windows XP Professional 32bit. I've tested your PLAREA.LSP and it works.

Message 9 of 12
ChuckB
in reply to: RKLindner

Thanks Richard. I really appreicate the help. I am having trouble modifying the code.  I keep getting "malformed list on input' on the command prompt after it loads. Granted, I'm extremely rusty.   Is the code you pasted from an Autodesk website that explains the changes that need to be made for routines in a 64b environment?  If so, would you mind sharing the URL?  Thanks again. 

Message 10 of 12
RKLindner
in reply to: ChuckB

Took me a bit to remember what I did too!  Anyway, the changes are incorporated into your routine and I have attached a new LSP file with them.  Take a look to see what I changed and what needed to be removed from your original.  Hope this works for you now.

Message 11 of 12
ChuckB
in reply to: RKLindner

WOW!  THANK YOU!!!  That works perfectly!  I was waaaay off.  I hope you get good karma in return Richard!

Message 12 of 12
RKLindner
in reply to: ChuckB

You are welcome.  Glad to help out others as I have been helped in the past.

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

Post to forums  

Autodesk Design & Make Report

”Boost