CesarA Posted January 15, 2016 Posted January 15, 2016 I'm trying to create a closed polyline like this: (defun c:pol (/ pt pt2 ptlist tmp myobj a) ;;;some random stuff I probably gotta put everytime (setq thisdrawing (vla-get-activedocument (vlax-get-acad-object))) (setq mspace (vla-get-modelspace thisdrawing)) ;;;select 1st point, assigned to variable pt (setq pt (getpoint "\nSpecify start point: ")) ;;;;assign the first point to a list, in this case ptlist (setq ptlist (cons pt ptlist)) ;;;select the following points, but these are cycled in variable pt2 (while (setq pt2 (getpoint "\nSpecify next point: " pt2)) (setq ptlist (cons pt2 ptlist)) ) ;;;repeat initial point so that the polyline is closed (setq ptlist (cons pt ptlist)) ;; "dissolve" the points into atoms with append: (setq ptlist (apply 'append ptlist)) (prin1 ptlist) ) The code would initially use variable ´pt´ to the first point and every following one and worked. But since i wanted to close it, I tought of assigning the 1st point to a exclusive variable, in that way, i would just have to repeat it at the end and I would have a closed polyline. Now I get error: bad argument type: point: nil Quote
CesarA Posted January 15, 2016 Author Posted January 15, 2016 I dunno why the first example didnt work, I had to create a new variable i that would count the number of while cycles, and then add the last element of the list (starting point) again, by looking directly into the list. Like this: (defun c:pol (/ pt pt2 ptlist tmp myobj a i) ;;;some random stuff I probably gotta put everytime (setq thisdrawing (vla-get-activedocument (vlax-get-acad-object))) (setq mspace (vla-get-modelspace thisdrawing)) ;;;select 1st point, assigned to variable pt (setq pt (getpoint "\nSpecify start point: ")) ;;;;assign the first point to a list, in this case ptlist (setq ptlist (cons pt ptlist)) (setq i 0) ;;;select the following points, this time they stay in pt2 or i will get a error (while (setq pt (getpoint "\nSpecify next point: " pt)) (setq i (+ i 1)) (setq ptlist (cons pt ptlist)) ) ;;;repeat initial point so that the polyline is closed (by going to the end of the list and adding the point again) (setq ptlist (cons (nth i ptlist) ptlist)) ;; "dissolve" the points into atoms with append: (setq ptlist (apply 'append ptlist)) (prin1 ptlist) (prin1 i) (setq tmp (vlax-make-safearray vlax-vbDouble (cons 0 (- (length ptlist) 1)) ) ) (vlax-safearray-fill tmp ptlist) (setq myobj (vla-addPolyline mspace tmp)) ) Next step: hatching it Quote
broncos15 Posted January 15, 2016 Posted January 15, 2016 I dunno why the first example didnt work, I had to create a new variable i that would count the number of while cycles, and then add the last element of the list (starting point) again, by looking directly into the list. Like this: (defun c:pol (/ pt pt2 ptlist tmp myobj a i) ;;;some random stuff I probably gotta put everytime (setq thisdrawing (vla-get-activedocument (vlax-get-acad-object))) (setq mspace (vla-get-modelspace thisdrawing)) ;;;select 1st point, assigned to variable pt (setq pt (getpoint "\nSpecify start point: ")) ;;;;assign the first point to a list, in this case ptlist (setq ptlist (cons pt ptlist)) (setq i 0) ;;;select the following points, this time they stay in pt2 or i will get a error (while (setq pt (getpoint "\nSpecify next point: " pt)) (setq i (+ i 1)) (setq ptlist (cons pt ptlist)) ) ;;;repeat initial point so that the polyline is closed (by going to the end of the list and adding the point again) (setq ptlist (cons (nth i ptlist) ptlist)) ;; "dissolve" the points into atoms with append: (setq ptlist (apply 'append ptlist)) (prin1 ptlist) (prin1 i) (setq tmp (vlax-make-safearray vlax-vbDouble (cons 0 (- (length ptlist) 1)) ) ) (vlax-safearray-fill tmp ptlist) (setq myobj (vla-addPolyline mspace tmp)) ) Next step: hatching it You could just use the hatch command on your newly created object "myobj". (command "._hatch" "_S" myobj "" "") Quote
CesarA Posted January 15, 2016 Author Posted January 15, 2016 It didn't work, because he wanted a point, and the polyline wasn't selected but even so, I think a simple command wouldn't be enough, I wanna choose a pattern and a scale as well. I'm trying to read the elipse hatch created by Lee-mac, it seems powerful and more flexible than that. This is just a piece of code of him that i commented (vla-appendouterloop ;means it will associate the boundaries with the hatch (setq hat ;hat is the hatch variable (vla-addhatch ;add hatch command (setq spc ;drawing space (vlax-get-property (vla-get-activedocument (vlax-get-acad-object));;; stuff i'm supposed to do everytime, probably change the hatch properties below (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace ) ) ) achatchpatterntypepredefined "SOLID" :vlax-true achatchobject ) ) (vlax-make-variant ;;;draws the hatch boundaries (i'll try to replace with the polyline) (vlax-safearray-fill (vlax-make-safearray vlax-vbobject '(0 . 0)) (list (vla-addellipse spc (vlax-3D-point (trans cen 1 0)) (vlax-3D-point (trans (mapcar '- maj cen) 1 0)) rat ) ) ) ) ) (vla-evaluate hat) Quote
broncos15 Posted January 15, 2016 Posted January 15, 2016 It didn't work, because he wanted a point, and the polyline wasn't selected but even so, I think a simple command wouldn't be enough, I wanna choose a pattern and a scale as well. I'm trying to read the elipse hatch created by Lee-mac, it seems powerful and more flexible than that. This is just a piece of code of him that i commented (vla-appendouterloop ;means it will associate the boundaries with the hatch (setq hat ;hat is the hatch variable (vla-addhatch ;add hatch command (setq spc ;drawing space (vlax-get-property (vla-get-activedocument (vlax-get-acad-object));;; stuff i'm supposed to do everytime, probably change the hatch properties below (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace ) ) ) achatchpatterntypepredefined "SOLID" :vlax-true achatchobject ) ) (vlax-make-variant ;;;draws the hatch boundaries (i'll try to replace with the polyline) (vlax-safearray-fill (vlax-make-safearray vlax-vbobject '(0 . 0)) (list (vla-addellipse spc (vlax-3D-point (trans cen 1 0)) (vlax-3D-point (trans (mapcar '- maj cen) 1 0)) rat ) ) ) ) ) (vla-evaluate hat) You can do it through the command line version by setting the variables HPSCALE (used for scale) in your code to what you want, as well as HPNAME (used for pattern), you just need to put them back at the end. If I understand you correctly, are you trying to basically live hatch by drawing a polyline and having it hatch in it? Just curious because I'll try to look into this code over the weekend and help. Sorry I haven't had to test it yet, also you can try to use entlast to select the last object. Quote
CesarA Posted January 15, 2016 Author Posted January 15, 2016 I've done it! Thank you broncos15. (vl-load-com) (defun c:outerloop1(/ acadObj doc patternName patternType bAssociativity modelSpace hatchObj center radius startAngle endAngle arc line outerLoop pt pt2 ptlist tmp myobj a i) ;; This example creates an associative hatch in model space, and ;; then creates an outer loop for the hatch. (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) ;; Define the hatch (setq patternName "ANSI31" patternType 0 bAssociativity :vlax-true) ;; Create the associative Hatch object (setq modelSpace (vla-get-ModelSpace doc)) (setq hatchObj (vla-AddHatch modelSpace patternType patternName bAssociativity acHatchObject)) ;;;select 1st point, assigned to variable pt (setq pt (getpoint "\nSpecify start point: ")) ;;;;assign the first point to a list, in this case ptlist (setq ptlist (cons pt ptlist)) (setq i 0) ;;;select the following points, but these are cycled in variable pt2 (while (setq pt (getpoint "\nSpecify next point: " pt)) (setq i (+ i 1)) (setq ptlist (cons pt ptlist)) ) ;;;repeat initial point so that the polyline is closed (setq ptlist (cons (nth i ptlist) ptlist)) ;; "dissolve" the points into atoms with append: (setq ptlist (apply 'append ptlist)) (prin1 ptlist) (prin1 i) ;; Create the outer loop for the hatch. ;; An arc and a line are used to create a closed loop. (setq tmp (vlax-make-safearray vlax-vbDouble (cons 0 (- (length ptlist) 1)) ) ) (vlax-safearray-fill tmp ptlist) (setq poly(vla-AddPolyline modelSpace tmp)) (setq outerLoop (vlax-make-safearray vlax-vbObject '(0 . 0))) (vlax-safearray-put-element outerLoop 0 poly) ;; Append the outer loop to the hatch object, and display the hatch (vla-AppendOuterLoop hatchObj outerLoop) (vla-Evaluate hatchObj) ) Btw ignore the commenting, i've meshed elements of different codes Quote
broncos15 Posted January 15, 2016 Posted January 15, 2016 I've done it! Thank you broncos15. (vl-load-com) (defun c:outerloop1(/ acadObj doc patternName patternType bAssociativity modelSpace hatchObj center radius startAngle endAngle arc line outerLoop pt pt2 ptlist tmp myobj a i) ;; This example creates an associative hatch in model space, and ;; then creates an outer loop for the hatch. (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) ;; Define the hatch (setq patternName "ANSI31" patternType 0 bAssociativity :vlax-true) ;; Create the associative Hatch object (setq modelSpace (vla-get-ModelSpace doc)) (setq hatchObj (vla-AddHatch modelSpace patternType patternName bAssociativity acHatchObject)) ;;;select 1st point, assigned to variable pt (setq pt (getpoint "\nSpecify start point: ")) ;;;;assign the first point to a list, in this case ptlist (setq ptlist (cons pt ptlist)) (setq i 0) ;;;select the following points, but these are cycled in variable pt2 (while (setq pt (getpoint "\nSpecify next point: " pt)) (setq i (+ i 1)) (setq ptlist (cons pt ptlist)) ) ;;;repeat initial point so that the polyline is closed (setq ptlist (cons (nth i ptlist) ptlist)) ;; "dissolve" the points into atoms with append: (setq ptlist (apply 'append ptlist)) (prin1 ptlist) (prin1 i) ;; Create the outer loop for the hatch. ;; An arc and a line are used to create a closed loop. (setq tmp (vlax-make-safearray vlax-vbDouble (cons 0 (- (length ptlist) 1)) ) ) (vlax-safearray-fill tmp ptlist) (setq poly(vla-AddPolyline modelSpace tmp)) (setq outerLoop (vlax-make-safearray vlax-vbObject '(0 . 0))) (vlax-safearray-put-element outerLoop 0 poly) ;; Append the outer loop to the hatch object, and display the hatch (vla-AppendOuterLoop hatchObj outerLoop) (vla-Evaluate hatchObj) ) Btw ignore the commenting, i've meshed elements of different codes No worries. I just tested your code and it works pretty well. If I was going to make a suggestion, why not make it "live" so that the user can see what they are hatching. You could do this with a while statement run on the user setting points: (while (setq ptn (getpoint ptn "\nSpecify next point: " ) ) . Within the while statement, draw the pline and immediate hatch it. 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.