BeachinIt Posted February 24, 2023 Posted February 24, 2023 (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! Quote
ronjonp Posted February 24, 2023 Posted February 24, 2023 (edited) The first step to becoming a proficient programmer is learning how to debug code. Open up the VLIDE and set break on error. Then load the selection: 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 February 24, 2023 by ronjonp 2 Quote
BIGAL Posted February 25, 2023 Posted February 25, 2023 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. 1 Quote
Steven P Posted February 25, 2023 Posted February 25, 2023 "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? 1 Quote
BIGAL Posted February 26, 2023 Posted February 26, 2023 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) 1 Quote
BeachinIt Posted February 27, 2023 Author Posted February 27, 2023 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) ) 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] Quote
Steven P Posted February 27, 2023 Posted February 27, 2023 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 Quote
BIGAL Posted February 27, 2023 Posted February 27, 2023 Just remove the (IF ) if happy that you always pick the right thing, I use a different way to force a correct object pick. Quote
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.