Jump to content

Error expected VLA-OBJECT at [vlax-invoke]


Recommended Posts

Posted
(defun c:draw-triangles-on-line ()
  (setq pline (car (entsel "\nSelect a polyline: ")))
  (setq numtri (getint "\nEnter the number of triangles: "))
  (setq vertices (vlax-invoke pline 'Vertices))
  (setq num-vertices (length vertices))
  (setq spacing (/ (vlax-curve-getDistAtParam pline (vlax-curve-getEndParam pline))
                    (+ numtri 1)))
  (setq startpt (vlax-curve-getStartPoint pline))
  (setq endpt (vlax-curve-getEndPoint pline))
  (setq midpoint (polar startpt (angle startpt endpt) (/ (distance startpt endpt) 2.0)))
  (setq vertex1 (polar midpoint (/ pi 2) (/ spacing 4.0)))
  (setq vertex2 (polar midpoint (/ (* 3 pi) 2) (/ spacing 4.0)))
  (setq i 0)
  (while (< i numtri)
    (setq pt1 (vlax-curve-getPointAtDist pline (+ spacing (* i spacing))))
    (setq pt2 (polar pt1 (angle startpt endpt) (/ (distance startpt endpt) 2.0)))
    (setq pt3 (polar pt2 (/ pi 2) (/ spacing 4.0)))
    (setq pt4 (polar pt2 (/ (* 3 pi) 2) (/ spacing 4.0)))
    (command "_.pline" pt3 pt4 pt2 "" pt1 "")
    (setq i (+ i 1))
  )
  (princ)
)

 

; ----- LISP : Call Stack -----
; [0]...C:DRAW-TRIANGLES-ON-LINE <<--
;
; ----- Error around expression -----
; (AL-ENAME2OBJ ENAME)
;
; error : bad argument type <<Entity name: 1c423a40>> ; expected VLA-OBJECT at [vlax-invoke]

 

1st box is the code, the 2nd box is my console output.
 

I believe my error is on line 3, but I'm uncertain what I'm doing wrong with this.

I'm looking to place triangles on a polyline where they are evenly intersected by a selected polyline, they will also be evenly spaced.

Any help is much appreciated!

Posted (edited)

The first step to becoming a proficient programmer is learning how to debug code. Open up the VLIDE and set break on error.

image.png.66a543f9297658db2b484a5f08cf686b.png

 

Then load the selection:

image.thumb.png.ecada4a9cb3ba4c89df3736c459d0663.png

 

There are a couple of issues with line 3: (setq vertices (vlax-invoke pline 'vertices))

vlax-invoke requires a VLA-OBJECT (vlax-ename->vla-object pline) and a polyline does not have a vertices property, it's coordinates.

 

Here is a common way to get LWPOLYLINE coordinates

(mapcar 'cdr (vl-remove-if '(lambda (x) (/= 10 (car x))) (entget pline)))

This returns ((X Y) (X Y) (X Y) (X Y))

 

Another way is like this which works on "heavy" polylines as well:

(vlax-get (vlax-ename->vla-object pline) 'coordinates)

This returns (X Y X Y X Y X Y)

 

It does not look like you're using the vertices variable for anything except setting the num-vertices variable ? An easier way to get that number is through the 90 DXF code.

(cdr (assoc 90 (entget pline)))
Edited by ronjonp
  • Like 2
Posted

Bricscad uses Blade not Vlide but similar approach to debugging code.

 

Not sure about this with no image or dwg to compare. (command "_.pline" pt3 pt4 pt2 "" pt1 "")

 

Always post an image or dwg helps sometimes way shorter and smarter solutions are offered.

  • Like 1
Posted

"bad argument type <<Entity name: 1c423a40>> ; expected VLA-OBJECT at [vlax-invoke]"

 

Tells you everything..... Argument - entity name - but it is expecting a VLA-Object at your line vlax-invoke

Or... you are using an entity name (pline) and the line wants a VLA-Object name.

 

(setq pline_Obj (vlax-ename->vla-object pline_Ent))

 

Should do that for you.

 

 

I couldn't find 'vertices (I don't do too much with VLA) - was giving me an error at that so got vertices by entget:

 

(defun c:DTOL ()
  (defun mAssoc ( key lst )
   (foreach x lst
     (if (= key (car x)) (setq l (cons (cdr x) l)) )
   )
   (reverse l)
  )

  (setq pline_Ent (car (entsel "\nSelect a polyline: ")))
  (setq numtri (getint "\nEnter the number of triangles: "))

(setq pline (vlax-ename->vla-object pline_Ent))
;;https://www.cadtutor.net/forum/topic/24364-vertices-of-a-polyline/
(setq vertices (mAssoc 10 (entget pline_Ent)) )


;  (setq vertices (vlax-invoke pline 'vertices))
  (setq num-vertices (length vertices))
  (setq spacing (/ (vlax-curve-getDistAtParam pline (vlax-curve-getEndParam pline))
                    (+ numtri 1)))
  (setq startpt (vlax-curve-getStartPoint pline))
  (setq endpt (vlax-curve-getEndPoint pline))
  (setq midpoint (polar startpt (angle startpt endpt) (/ (distance startpt endpt) 2.0)))
  (setq vertex1 (polar midpoint (/ pi 2) (/ spacing 4.0)))
  (setq vertex2 (polar midpoint (/ (* 3 pi) 2) (/ spacing 4.0)))
  (setq i 0)
  (while (< i numtri)
    (setq pt1 (vlax-curve-getPointAtDist pline (+ spacing (* i spacing))))
    (setq pt2 (polar pt1 (angle startpt endpt) (/ (distance startpt endpt) 2.0)))
    (setq pt3 (polar pt2 (/ pi 2) (/ spacing 4.0)))
    (setq pt4 (polar pt2 (/ (* 3 pi) 2) (/ spacing 4.0)))
    (command "_.pline" pt3 pt4 pt2 "" pt1 "")
    (setq i (+ i 1))
  )
  (princ)
)

 

 

Though the triangles part wasn't quote working for me - you can adjust that though?

 

 

  • Like 1
Posted

Need an image.

 

Like Steven P

 

(setq plent (entsel "\nPick pline"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
(princ co-ord)

 

  • Like 1
Posted

UPDATED FUNCTION from @Steven P 

(defun c:DTOL ()
  (defun mAssoc ( key lst )
   (foreach x lst
     (if (= key (car x)) (setq l (cons (cdr x) l)) )
   )
   (reverse l)
  )

;  (setq pline_Ent (car (entsel "\nSelect a polyline: ")))
  (setq pline_Ent (entsel "\nPick pline"))
  (if pline_Ent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
  (princ co-ord)
  (setq numtri (getint "\nEnter the number of triangles: "))

(setq pline (vlax-ename->vla-object pline_Ent))
;;https://www.cadtutor.net/forum/topic/24364-vertices-of-a-polyline/
;;;(setq vertices (mAssoc 10 (entget pline_Ent)) )


;  (setq vertices (vlax-invoke pline 'vertices))
;;;  (setq num-vertices (length vertices))
  (setq spacing (/ (vlax-curve-getDistAtParam pline (vlax-curve-getEndParam pline))
                    (+ numtri 1)))
  (setq startpt (vlax-curve-getStartPoint pline))
  (setq endpt (vlax-curve-getEndPoint pline))
  (setq midpoint (polar startpt (angle startpt endpt) (/ (distance startpt endpt) 2.0)))
  (setq vertex1 (polar midpoint (/ pi 2) (/ spacing 4.0)))
  (setq vertex2 (polar midpoint (/ (* 3 pi) 2) (/ spacing 4.0)))
  (setq i 0)
  (while (< i numtri)
    (setq pt1 (vlax-curve-getPointAtDist pline (+ spacing (* i spacing))))
    (setq pt2 (polar pt1 (angle startpt endpt) (/ (distance startpt endpt) 2.0)))
    (setq pt3 (polar pt2 (/ pi 2) (/ spacing 4.0)))
    (setq pt4 (polar pt2 (/ (* 3 pi) 2) (/ spacing 4.0)))
    (command "_.pline" pt3 pt4 pt2 "" pt1 "")
    (setq i (+ i 1))
  )
  (princ)
)


image.thumb.png.86ed237957491d01cc9707084a5aedef.png

I used the code from @Steven P and updated line of picking the line with console output from @BIGAL.  Thank you both for looking at this post and helping btw.

I ended up choosing the level line (at the very top) and received that console output.  Complaining that I'm missing an entity name

GOAL: I'm looking to place triangles on a polyline where they are evenly intersected by a selected polyline, they will also be evenly spaced.
---|>---|>---
 

; error : bad argument type <(<Entity name: 6303b640> (4.41025118198951 6.48940258141088 0.0))> ; expected ENTITYNAME at [vlax-ename->vla-object]
: DTOL
Pick pline((3.0 4.8) (11.5999989906226 4.80416668817499))
Enter the number of triangles: 2

; ----- LISP : Call Stack -----
; [0]...C:DTOL <<--
;
; ----- Error around expression -----
; (AL-ENAME2OBJ ENAME)
;
; error : bad argument type <(<Entity name: 5e007c20> (5.24157286165867 7.15019673704534 0.0))> ; expected ENTITYNAME at [vlax-ename->vla-object]
Posted

You might to use this line:

 

(if pline_Ent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car pline_ent))))))

 

and not

(if pline_Ent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))

 

Should fix the error

Posted

Just remove the (IF  )  if happy that you always pick the right thing, I use a different way to force a correct object pick.

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...