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

error: bad argument type: VLA-OBJECT nil

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
11763 Views, 8 Replies

error: bad argument type: VLA-OBJECT nil

I receive this error from the attached lisp routine and have not been able to figure out the problem. I received this file form a very nice group member a couple of days ago and would like to use if I get it debugged. he cobbled it together form an old string he posted years ago. The routine exports the x,y,z coordinates of the selected polylines and the layer name to a csv file.

Any help would be appreciated.

KH
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

Hmmm.....
I just tested the code and cannot get it to fail. Oops! Hold on, I see the
problem......I have a global variable that is always set that I reference in
that code....

Add this line directly below the (vl-load-com) line, then save & reload the
lisp file:

(setq *doc* (vla-get-activedocument (vlax-get-acad-object)))

That should do it.
Sorry 'bout that!


wrote in message news:5632905@discussion.autodesk.com...
I receive this error from the attached lisp routine and have not been able
to figure out the problem. I received this file form a very nice group
member a couple of days ago and would like to use if I get it debugged. he
cobbled it together form an old string he posted years ago. The routine
exports the x,y,z coordinates of the selected polylines and the layer name
to a csv file.

Any help would be appreciated.

KH
Message 3 of 9
Anonymous
in reply to: Anonymous

Jeff,
That did it thank you. I didn't realize that the utility only exported the start and end points of the polyline. I have polylines that have multiple vertices (river cross sections) and need to export all. What I can do is just explode the polylines into line segments and then export from there. What will happen is there will be multiple duplicate X, Y points but can weed out in excel I suppose. Thank you very much for your assistance.

KH
Message 4 of 9
Anonymous
in reply to: Anonymous

Hi Kurt. You are quite welcome.

Are your polylines 3d polys? If so, I'm surprised it works at all for you.
After looking at the routine, I'm sure it could be streamlined (like I said
before, this was written when I was first getting into using the ActiveX)
and be revised to do what you need.

I'll post back with soemthing that should work better.

wrote in message news:5633482@discussion.autodesk.com...
Jeff,
That did it thank you. I didn't realize that the utility only exported the
start and end points of the polyline. I have polylines that have multiple
vertices (river cross sections) and need to export all. What I can do is
just explode the polylines into line segments and then export from there.
What will happen is there will be multiple duplicate X, Y points but can
weed out in excel I suppose. Thank you very much for your assistance.

KH
Message 5 of 9
Anonymous
in reply to: Anonymous

Jeff,
Not 3d polylines. Individual pline segments. The cross sections were created in LDD and displayed in 2D. The z value is redundent because all I need is the X and Y. I have this other routine that will export all the vertices of a polyline but not the layer (see attached).

KH
Message 6 of 9
Anonymous
in reply to: Anonymous

OK, so I guess the version that outputs this wouldn't be any good?

Coordinate dump with LAYER
Line on layer 0
5.5138,14.1206,0.0000,10.8269,13.3799,0.0000
2dPolyline on layer 0
13.4834,15.4170,0.0000,14.4623,16.4663,0.0000,15.8001,16.6824,0.0000,16.6420,16.0676,0.0000,17.4373,15.5404,0.0000,18.8165,16.1499,0.0000,20.3718,16.9911,0.0000,21.1669,16.9596,0.0000
Polyline on layer 0
13.1745,12.7317,0.0000,14.8425,14.1206,0.0000,19.4142,11.0342,0.0000,21.0823,13.3799,0.0000
3dPolyline on layer 0
8.1086,6.9909,0.0000,10.2709,9.7996,0.0000,14.5645,7.7008,0.0000,15.7383,10.1391,0.0000



wrote in message news:5633644@discussion.autodesk.com...
Jeff,
Not 3d polylines. Individual pline segments. The cross sections were
created in LDD and displayed in 2D. The z value is redundent because all I
need is the X and Y. I have this other routine that will export all the
vertices of a polyline but not the layer (see attached).

KH
Message 7 of 9
Anonymous
in reply to: Anonymous

That would work (all will be 2d polylines) really nicely. See attached spreadsheet sample format. The layers I'm exporting correspond to the dates.

KH
Message 8 of 9
Anonymous
in reply to: Anonymous

OK, here's a revised lips that works with Polylines & LWPolylines. I removed
the portion that prints what type it is, so there will be a line with the
layer name, followed by a line with the XYZ's.

[code]
;| Code to output the coordinates, with layer info, of selected
polylines by Jeff Mishler. June 2007.
|;
(vl-load-com)

(defun c:getxyz (/ fname)
(initget 1)
(setq fname
(getstring
"\nName of file to write to, will add extension of .csv to name: "
)
)
(if fname
(getxyzLay fname)
)
(princ)
)

(defun getxyzLay (fname / coords fh fpath lay coordstr oname param sS
)
(if (ssget '((0 . "LWPOLYLINE,POLYLINE")))
(progn
(setq ss (vla-get-activeselectionset (vla-get-activedocument
(vlax-get-acad-object))))
(if (not (setq fpath (findfile (strcat fname ".csv"))))
(progn
(setq fpath (getfiled "File to Open" fname "csv" 1))
)
)
(setq fH (open fpath "w"))
(write-line
"XYZ Coordinate dump with LAYER"
fH
)
(vlax-for ent ss
(setq oname (vla-get-objectname ent))
(if (= oname "AcDbLine")
(progn
(setq coords (append (vlax-curve-getstartpoint ent)
(vlax-curve-getendpoint ent)
)
)
)
(progn
(setq param 0)
(setq coords (vlax-curve-getstartpoint ent))
(while (<= (setq param (1+ param)) (vlax-curve-getendparam ent))
(setq coords (append coords (vlax-curve-getpointatparam ent param)))
)
)
)
(setq lay (vla-get-layer ent))
(setq coordstr (vl-princ-to-string (mapcar '(lambda (x)
(rtos x 2 4)
)
coords
)
))
(setq coordstr (vl-string-subst "" "(" coordstr)
coordstr (vl-string-subst "" ")" coordstr)
)
(while (vl-string-search " " coordstr)
(setq coordstr (vl-string-subst "," " " coordstr))
)
(write-line lay FH)
(write-line coordstr fH)
)
(close fH)
)
)
(princ)
)
[/code]

wrote in message news:5633954@discussion.autodesk.com...
That would work (all will be 2d polylines) really nicely. See attached
spreadsheet sample format. The layers I'm exporting correspond to the
dates.

KH
Message 9 of 9
Anonymous
in reply to: Anonymous

Jeff,
Thank you very much for the help. I think between the two routines I will be able to export and manipulate in excel after the fact. In the perfect world the xyz coords would be in 2 columns and not in one row/string. Like I said I will be able to manipulate after export. Thanks again, I'm sure glad your posting on this group page.

Kurt

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

Post to forums  

Autodesk Design & Make Report

”Boost