PDA

View Full Version : lisp worked in 07 doesn't work in 09?


03xtreme
2009-08-06, 09:43 PM
(defun attsurf (bname / acadobj aecapp aecProj aecsurfs aecsurf aecutil e-n
emsg pt# selev appstr versn *error* att blk space)
(defun *error* (msg / objlist)
(setq objList
(reverse
(list acadobj aecapp aecProj aecsurfs aecsurf aecutil)
)
)
(vl-catch-all-apply
'(lambda ()
(mapcar 'vlax-release-object objlist)
)
)
(if msg
(princ (strcat "\n" msg))
)
(princ)
)
;;;;;
(setq appstr (cond ((= (setq versn (atoi (substr (getvar "acadver") 1 2))) 15) "2")
((= versn 16) "4")
((= versn 17) "6")
)
)
(setq acadObj (vlax-get-acad-object)
space (vla-get-modelspace (vla-get-activedocument acadObj))
aecApp (vla-getinterfaceobject acadObj (strcat "Aecc.Application." appstr))
aecProj (vlax-get aecApp "Activeproject")
aecSurfs (vlax-get aecProj "Surfaces")
aecSurf (vlax-get aecSurfs "Currentsurface")
aecUtil (vlax-get (vlax-get aecApp "activedocument") "Utility")
)
(if (and (= aecSurf "")
(> (vlax-get aecSurfs "count") 0)
)
(setq aecSurf (vlax-get (vlax-invoke aecSurfs "item" 0) "name"))
)
(if (= aecSurf "")
(princ
"\nNo surfaces defined, try again after creating a surface."
)
(progn
(setq aecSurf (vlax-invoke aecSurfs "item" aecSurf))
(while (setq
pt# (getpoint "\nPoint to label on the current surface: ")
)
(setq e-n (vlax-invoke aecutil "xytoeastnorth" pt#))
(setq selev (vlax-invoke
aecSurf
"getelevation"
(car e-n)
(cadr e-n)
)
)
;;Insert your block insertion and attribute setting here
(setq blk (vlax-invoke space 'insertblock pt# bname 1.0 1.0 1.0 0.0))
(setq att (car (vlax-invoke blk 'getattributes)))
(vla-put-textstring att (rtos selev 2 2))
;(princ (strcat "\nElevation at point = " (rtos selev)))
)
)
)
(*error* nil)
)


;;;make as many of these as you need, this is for the SPOTL40 block
(defun c:SPOTR (/ bname)
(setq bname "SPoTR40");;set the block name in this line
(if (or (tblsearch "BLOCK" bname)
(setq bname (findfile bname))
)
(attsurf bname)
)
(princ)
)


automation error. problem in loading the application....

thanks for any help on this.

irneb
2009-08-06, 11:40 PM
What happens if you type (vl-load-com) at the command prompt? If correct nothing should be shown.

03xtreme
2009-08-06, 11:45 PM
thats correct, nothing happens, thanks for helping so quickly by the way.

irneb
2009-08-07, 12:05 AM
Ok final try (vlax-get-acad-object) ... was around here anyway.

It should return something like:
#<VLA-OBJECT IAcadApplication 00d74d3c>

03xtreme
2009-08-07, 03:48 PM
Ok final try (vlax-get-acad-object) ... was around here anyway.

It should return something like:
#<VLA-OBJECT IAcadApplication 00d74d3c>

#<VLA-OBJECT IAcadApplication 00cdb528>

is returned, not what you wrote, unfortunately, but maybe this is the problem?

RobertB
2009-08-07, 05:14 PM
No, the function returned the AutoCAD application interface, which is correct. The memory addres does not matter.

However, the file should include the statement (vl-load-com) at the beginning, before the attsurf definition, since the code uses the ActiveX interface.

(vl-load-com) only needs to be run once per AutoCAD session, to load the ActiveX interface. But it does not hurt to execute it more. And when you place the statement at the beginning of any file that uses the interface you can be sure the interface is loaded when that code is loaded.

It is apparent that the issue is this statement:
(setq aecApp (vla-getinterfaceobject acadObj (strcat "Aecc.Application." appstr)))

appstr is set by this statement:
(setq appstr (cond ((= (setq versn (atoi (substr (getvar "acadver") 1 2))) 15) "2")
((= versn 16) "4")
((= versn 17) "6")))

So I'm betting the progID is different for AutoCAD 2009. Search the registry for "Aecc.Application." to determine the new progID.

03xtreme
2009-08-07, 05:29 PM
It is apparent that the issue is this statement:
(setq aecApp (vla-getinterfaceobject acadObj (strcat "Aecc.Application." appstr)))

appstr is set by this statement:
(setq appstr (cond ((= (setq versn (atoi (substr (getvar "acadver") 1 2))) 15) "2")
((= versn 16) "4")
((= versn 17) "6")))

So I'm betting the progID is different for AutoCAD 2009. Search the registry for "Aecc.Application." to determine the new progID.

Under the class root i found the aecc.application and the aecc.application.8
aecc.application/CurVer value is "aecc.application.8"

and the acadversion is 17.2 but i don't know how that equates to the code above? The aeccversion is set to 60 in the local machine registry

RobertB
2009-08-07, 06:10 PM
Under the class root i found the aecc.application and the aecc.application.8
aecc.application/CurVer value is "aecc.application.8"

and the acadversion is 17.2 but i don't know how that equates to the code above? The aeccversion is set to 60 in the local machine registry

Simple enough, given that information:

(setq appstr (cond ((= (fix (setq versn (atof (getvar "acadver")))) 15) "2")
((= (fix versn) 16) "4")
((< versn 17.2) "6")
((= versn 17.2) "8")))

03xtreme
2009-08-07, 06:14 PM
perfect and thank you, learn something everyday....

RobertB
2009-08-07, 06:22 PM
perfect and thank you, learn something everyday....
Happy to help and thanks for the rep!