Jump to content

Area Lisp Routine error in Autocad 2011 and Win 7 64bit


Davidg1230

Recommended Posts

Hi, new to the forum, but thought I'd ask for some help with a routine that seems to have stopped working. I guess plenty of others are having problems with lisp routines failing after upgrading to other platforms.

 

The situation is, I've upgraded from a Win XP (32 bit) pc running AutoCAD 2010 to a 64 bit Win 7 machine running 2011.

 

It appears that whilst some routines still work, a routine that calculates the area of a closed polyline and writes the area in sq.m and sq.ft now fails to print the correct values. The routine works still, but the values are now shown as ### / #### and not 100m2 / 1000sqft (for example)

 

Routine is as follows;

 

(defun c:AMF ()
(vl-load-com)
;;get a reference to model space
(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 )
;;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 string - this creates the field
str (strcat
"%<\\AcObjProp.16.2 Object(%<\\_ObjId "(rtos objID 2 0)">%).Area \\f 
\"%lu2%pr0%ct8[1e-006]%qf1 m²\">%"
" / "
"%<\\AcObjProp.16.2 Object(%<\\_ObjId "(rtos objID 2 0)">%).Area \\f 
\"%lu2%pr0%ct8[1.0763910417e-005]%qf1 ft²\">%"
)
)
)
;; 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)
(setq #ela (getvar "clayer"))
(command "_insert" "*WDE__Layers" "0,0,0" "1" "0" "-layer" "t" "A080T1" "on" "A080T1" "m" "A080T1" "" "" "-purge" "la" "*" "n") 
(setq #ds (getvar "dimscale"))
(setq #th (* 2.5 #ds))
(command "text" "s" "WDE_Arial" "J" "M" b #th "" str )
(setvar "clayer" #ela)
(princ)
) 

 

I didn't write this routine, but the guy who did no longer works for the company and we can't seem to work out what's causing this? Any help would be appreciated, thanks

Link to comment
Share on other sites

If I remember correctly, try replacing vla-get-objectid with vla-get-objectid32.

 

Oh yeah, and welcome to CADTutor - the place of info and trollers. :lol:

Link to comment
Share on other sites

Thanks Alanjt, tried that, still doesn't work:( i can manually select 'object' in the fields dialogue box and then select 'Area', get the value needed but it just won't enter the correct value as text?

 

I'm out of my depth here and can only play around with the existing routine:roll:

Link to comment
Share on other sites

Haven't got time to mess around with all the layers etc, but this should give you a nudge in the right direction:

 

(defun c:AMF ( / LM:Select LM:GetObjectID acdoc acspc e i o p ) (vl-load-com)

 (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
       acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))
 )

 (defun LM:Select ( msg pred fun / e ) (setq pred (eval pred))
   ;; © Lee Mac 2011
   (while
     (progn (setvar 'ERRNO 0) (setq e (car (fun msg)))      
       (cond
         ( (= 7 (getvar 'ERRNO))

           (princ "\n** Missed, Try again **")
         )
         ( (eq 'ENAME (type e))

           (if (and pred (not (pred e)))
             (princ "\n** Invalid Object Selected **")
           )
         )
       )
     )
   )
   e
 )

 (defun LM:GetObjectID ( doc obj )
   ;; © Lee Mac 2011
   (if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
     (vlax-invoke-method (vla-get-Utility doc) 'GetObjectIdString obj :vlax-false)
     (itoa (vla-get-Objectid obj))
   )
 )
 
 (if
   (and
     (setq e
       (LM:Select "\nSelect Object: "
         (function
           (lambda ( x ) (vlax-property-available-p (vlax-ename->vla-object x) 'Area))
         )
         entsel
       )
     )
     (setq p (getpoint "\nSelect Point: "))
     (setq i (LM:GetObjectID acdoc (vlax-ename->vla-object e)))
   )
   (progn
     (setq o
       (vla-AddText acspc
         (strcat
           "%<\\AcObjProp.16.2 Object(%<\\_ObjId " i ">%).Area \\f \"%lu2%pr0%ps[, m²]%ct8[1e-006]\">%"
           " / "
           "%<\\AcObjProp.16.2 Object(%<\\_ObjId " i ">%).Area \\f \"%lu2%pr0%ps[, ft²]%ct8[1.0763910417e-005]\">%"
         )
         (setq p (vlax-3D-point (trans p 1 0)))
         (* 2.5 (cond ( (zerop (getvar 'DIMSCALE)) 1.) ( (getvar 'DIMSCALE) )))
       )
     )
     
     (vla-put-Alignment o acalignmentmiddle)
     (vla-put-TextAlignmentPoint o p)
     
     (if (not (tblsearch "LAYER" "A080T1"))
       (vla-Add (vla-get-layers acdoc) "A080T1")
     )
     (vla-put-layer o "A080T1")
     
     (if (not (tblsearch "STYLE" "WDE_Arial"))
       (vla-Add (vla-get-textstyles acdoc) "WDE_Arial")
     )
     (vla-put-Stylename o "WDE_Arial")
   )
 )

 (princ)
)

Edited by Lee Mac
Link to comment
Share on other sites

Thanks Lee, that works perfectly, just need to sort the layers out, but for now I can change that manually.

 

So what was the issue? is it the way the code has been written, or an issue with Win 7 64bit?

 

Thanks again:D

Edited by Davidg1230
Link to comment
Share on other sites

Thanks Lee, that works perfectly, just need to sort the layers out, but for now I can change that manually.

 

You're welcome :) The layers could also be coded into the routine if necessary.

 

So what was the issue? is it the way the code has been written, or an issue with Win 7 64bit?

 

It was because the program was being run on a 64-bit system - the method for retrieving the ObjectID as a string for 64-bit systems differs from that used on 32-bit systems.

 

Also, the routine had little to no error trapping, so I added that also.

 

Lee

Link to comment
Share on other sites

If you do get a chance to add the layer confirguration aswell that would be great. :D

 

If we updated this routine and rolled it out for everyone, would this new one still work on older 32bit machines?

 

Thanks again.

Link to comment
Share on other sites

If you do get a chance to add the layer confirguration aswell that would be great. :D

 

I'll see what I can do. Looking at the original routine, the code would insert a block (presumably containing all the layers/textstyles), then perform a purge. It would be better if the layers/textstyle were either imported on startup, or if you used a template.

 

If we updated this routine and rolled it out for everyone, would this new one still work on older 32bit machines?

 

Of course :)

Link to comment
Share on other sites

We do use multiple templates, but each is project specific so it's hard to use a generic template when AutoCAD first boots. If it's tricky to use original config. then don't worry, I can manually match the layers.:)

 

EDIT: Beat me to it....doh!

Link to comment
Share on other sites

We do use multiple templates, but each is project specific so it's hard to use a generic template when AutoCAD first boots. If it's tricky to use original config. then don't worry, I can manually match the layers.:)

 

I could code the original setup, inserting a block, exploding and purging - but its not the ideal way to approach it, let along not the fastest.

 

Happy to help :)

Link to comment
Share on other sites

I could code the original setup, inserting a block, exploding and purging - but its not the ideal way to approach it, let along not the fastest.

 

Happy to help :)

Agree with you, but if you only wanted styles/layers, you'd only have to insert the definition and cancel the rest of the insert command (if taking such a route).
Link to comment
Share on other sites

Agree with you, but if you only wanted styles/layers, you'd only have to insert the definition and cancel the rest of the insert command (if taking such a route).

 

Ah - good point, just something like:

 

(command "_.-insert" "WDE__Layers") (command)

Link to comment
Share on other sites

Ah - good point, just something like:

 

(command "_.-insert" "WDE__Layers") (command)

Right, or:

(command "_.-insert" "WDE__Layers" nil)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...