Davidg1230 Posted March 28, 2011 Share Posted March 28, 2011 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 28, 2011 Share Posted March 28, 2011 Hi David, Firstly, welcome to CADTutor, you've navigated to the best forum board on the site Have a read of this post for details on how to post code: http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines Lee Quote Link to comment Share on other sites More sharing options...
Davidg1230 Posted March 28, 2011 Author Share Posted March 28, 2011 Thanks, updated post.... Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 28, 2011 Share Posted March 28, 2011 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. Quote Link to comment Share on other sites More sharing options...
Davidg1230 Posted March 28, 2011 Author Share Posted March 28, 2011 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: Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 28, 2011 Share Posted March 28, 2011 (edited) 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 March 28, 2011 by Lee Mac Quote Link to comment Share on other sites More sharing options...
Davidg1230 Posted March 28, 2011 Author Share Posted March 28, 2011 (edited) 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 March 28, 2011 by Davidg1230 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 28, 2011 Share Posted March 28, 2011 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 Quote Link to comment Share on other sites More sharing options...
Davidg1230 Posted March 28, 2011 Author Share Posted March 28, 2011 If you do get a chance to add the layer confirguration aswell that would be great. If we updated this routine and rolled it out for everyone, would this new one still work on older 32bit machines? Thanks again. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 28, 2011 Share Posted March 28, 2011 If you do get a chance to add the layer confirguration aswell that would be great. 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 28, 2011 Share Posted March 28, 2011 Updated to use correct Layer/Style - the layer and style will be created if non-existent. Lee Quote Link to comment Share on other sites More sharing options...
Davidg1230 Posted March 28, 2011 Author Share Posted March 28, 2011 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! Quote Link to comment Share on other sites More sharing options...
Davidg1230 Posted March 28, 2011 Author Share Posted March 28, 2011 New routine works perfectly:D Another happy customer:thumbsup: Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 28, 2011 Share Posted March 28, 2011 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 Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 28, 2011 Share Posted March 28, 2011 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). Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 28, 2011 Share Posted March 28, 2011 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) Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 28, 2011 Share Posted March 28, 2011 Ah - good point, just something like: (command "_.-insert" "WDE__Layers") (command) Right, or: (command "_.-insert" "WDE__Layers" nil) Quote Link to comment Share on other sites More sharing options...
amarcon Posted March 29, 2011 Share Posted March 29, 2011 Right, or: (command "_.-insert" "WDE__Layers" nil) Right, or the old style: (command "_.-insert" "WDE__Layers" ^C) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.