autolisper Posted January 22, 2020 Posted January 22, 2020 Hi All, I am trying to draw a pline by connecting all the vertices of the mline. Below is my code, but it gives an error saying; error: bad argument type: fixnump: (vl-load-com) (defun c:hl_mltopline () (setq mspace (vla-get-modelSpace (vla-get-activeDocument (vlax-get-acad-object) ) ) ) (setq ml (vlax-ename->vla-object (car (entsel "\nPick a multiline: ")) ) ) (setq coord (vlax-safearray->list (vlax-variant-value (vla-get-coordinates ml)))) (setq pl_points_safearray (vlax-make-safearray vlax-vbDouble pl_points_list)) (setq pline (vla-addlightweightpolyline mspace )) (entmod pline) ) Could someone please help me fix this? Thanks in advance..!! Quote
Lee Mac Posted January 22, 2020 Posted January 22, 2020 There are many issues with your code - You define a variable 'coord' as the coordinates of the mline, but then supply vlax-make-safearray with the variable 'pl_points_list'. You are not supplying all of the required arguments for the addlightweightpolyline method, only the block container argument 'mspace'. The addlightweightpolyline method returns a vla-object, not an entity name which may be used with the entmod function. You are not declaring your local variables. You are not accounting for null user input. You are not accounting for the user selecting objects other than multilines. 1 Quote
BIGAL Posted January 23, 2020 Posted January 23, 2020 (edited) Try this, there are other ways like entmake. (defun c:hl_mltopline ( / mspace ent coords pline) (while (and (setq ent (car (entsel "\nPick a multiline Enter to exit : "))) (= (cdr (assoc 0 (entget ent))) "MLINE") ) (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) (setq coords (vlax-safearray->list (vlax-variant-value (vla-get-coordinates (vlax-ename->vla-object ent))))) (setq tmp (vlax-make-safearray vlax-vbDouble (cons 0 (- (length coords) 1)))) (vlax-safearray-fill tmp coords) (setq myobj (vla-addPolyline mspace tmp)) ) (princ) ) Maybe do a search next time 1st this is 3 years old and has lee's solution as well. Edited January 24, 2020 by BIGAL Quote
autolisper Posted January 23, 2020 Author Posted January 23, 2020 Dear Lee, Though I had started to explore Autolisp some years back, I could not continue my learning. Now recently I restarted exploring and its hardly a couple of months. Thanks a lot for your time and effort for pointing out the mistakes and for the advise.... Quote
autolisper Posted January 23, 2020 Author Posted January 23, 2020 (edited) Dear Bigal, Thanks for the code. I tried it. It gives the following error; error: lisp value has no coercion to VARIANT with this type: But your code below worked exactly as I wanted... https://www.cadtutor.net/forum/topic/63755-lisp-to-convert-a-mline-to-a-single-pline/?do=findComment&comment=525461 Thanks a lot..!! Edited January 23, 2020 by autolisper Quote
Lee Mac Posted January 23, 2020 Posted January 23, 2020 13 hours ago, autolisper said: Dear Lee, Though I had started to explore Autolisp some years back, I could not continue my learning. Now recently I restarted exploring and its hardly a couple of months. Thanks a lot for your time and effort for pointing out the mistakes and for the advise.... You're most welcome. On this subject, you might find this program useful. Quote
BIGAL Posted January 24, 2020 Posted January 24, 2020 (edited) Odd re HL_MLTOPLINE above maybe its a Briscad thing and it works no errors draws a pline. I set the layer to another so could see it make pline ie not white colour. Edited January 24, 2020 by BIGAL Quote
Roy_043 Posted January 24, 2020 Posted January 24, 2020 7 hours ago, BIGAL said: maybe its a Briscad thing BricsCAD is more lenient when it comes to arguments for VL* functions. Quote
BIGAL Posted January 24, 2020 Posted January 24, 2020 (edited) Checked in Autocad and got error fixed, now works in Autocad and Briscad. Thanks Roy_043 Edited January 24, 2020 by BIGAL Quote
Roy_043 Posted January 25, 2020 Posted January 25, 2020 What you have done is strange: First you convert a variant to a list then you convert the list to a variant. Also look at vlax-get/vlax-put. Quote
Lee Mac Posted January 25, 2020 Posted January 25, 2020 3 hours ago, Roy_043 said: What you have done is strange: First you convert a variant to a list then you convert the list to a variant. To be fair to the OP, the safearray variants used by the coordinates property of an MLINE & LWPOLYLINE object are of different dimensions (the MLINE requires 3D coordinates, whereas the LWPOLYLINE requires 2D coordinates), and so the conversion (or some form of list manipulation if using vlax-get/vlax-put) would be required. BricsCAD may be more tolerant in this regard. Quote
Roy_043 Posted January 25, 2020 Posted January 25, 2020 BricsCAD is not that tolerant. I was commenting on Bigal's revised code. The issue you mention does not apply there. Quote
Lee Mac Posted January 25, 2020 Posted January 25, 2020 23 minutes ago, Roy_043 said: BricsCAD is not that tolerant. I was commenting on Bigal's revised code. The issue you mention does not apply there. Sorry - I thought you were commenting on the OP's code, which performs the same conversion. Quote
BIGAL Posted January 26, 2020 Posted January 26, 2020 Quick answer from me is that I would not normally use (vla-addPolyline rather entmake or a command method as the list is xyz xyz xyz I would just make a point using list of nth's. Quote
ronjonp Posted January 27, 2020 Posted January 27, 2020 Code simplified per @Roy_043 suggestions. (defun c:hl_mltopline (/ ent sp) (while (and (setq ent (car (entsel "\nPick a multiline Enter to exit : "))) (= (cdr (assoc 0 (entget ent))) "MLINE") ) (or sp (setq sp (vlax-ename->vla-object (cdr (assoc 330 (entget ent)))))) (vlax-invoke sp 'addpolyline (vlax-get (vlax-ename->vla-object ent) 'coordinates)) ) (princ) ) 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.