Boundary command analogue

Kirillspec
Contributor
Contributor

Boundary command analogue

Kirillspec
Contributor
Contributor

Hello everyone!
Does anybody knows algorithm of working a Boundary command in AutoCad?
This command is very slow for my task, so I want to create more faster analogue in Autolisp. I just need to draw a boundary by picking point inside closed contour surrounded by intersected lines and polylines segments. Can someone help to solve this task?

0 Likes
Reply
Accepted solutions (1)
304 Views
11 Replies
Replies (11)

Moshe-A
Mentor
Mentor

@Kirillspec  hi,

 

Well this is totally depend on the load dwg you have. if you working on a heavy file it will take more time to find the boundary (the same for adding hatch).

 

Before AutoCAD gave us the option to pick point for boundary (do not remember what version it was but sure a decade or two already passed) we had to have a close area or trace it with polyline and AutoCAD did it fast. this process is not changed. what changed is we have pick point now...when you use this option you sending AutoCAD to find the boundary from all it 'sees' on screen and thus could be a lot of objects to find from so to overcome this they also gave us another option you can use called 'Boundary Set' where you can narrow the amount of objects AutoCAD will process in order to find your closed area.

 

Sounds logic?

 

Moshe

 

 

 

 

 

0 Likes

Kirillspec
Contributor
Contributor

Yes I know that it depends on the size of drawing, but even in a small size drawing when you deals with 100k boundaries it takes a lot of time to generate 100k boundaries. I believe that using custom command can raise speed significantly.

thank you for the tips about Boundary set , it seems slightly increase speed, but seems generates not precise boundaries.

0 Likes

Moshe-A
Mentor
Mentor

What do you mean by 100k?

The file size is 100kb?

Or

You have 100 * 1024 boundaries do draw?

0 Likes

CADaSchtroumpf
Advisor
Advisor

Just for try, if can be more faster.

If it the case, it can be modified for your convenience.

 

(vl-load-com)
(defun c:surf_curve-closed ( / AcDoc Space loop js pt_in new_pl area_obj nw_obj ename ent_text dxf_ent key)
	(setq
		AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
		Space
		(if (= 1 (getvar "CVPORT"))
			(vla-get-PaperSpace AcDoc)
			(vla-get-ModelSpace AcDoc)
		)
		loop T
	)
	(princ "\nSelect a closed object or <Enter/Right-click> for a point in interior of area")
	(while loop
		(setq
			js
			(ssget "_+.:E:S"
				'(
					(-4 . "<OR")
						(-4 . "<AND")
							(0 . "*POLYLINE")
							(-4 . "<AND")
								(-4 . "<NOT") (-4 . "&") (70 . 120) (-4 . "NOT>")
								(-4 . "&") (70 . 1)
							(-4 . "AND>")
						(-4 . "AND>")
						(0 . "CIRCLE")
						(-4 . "<AND")
							(0 . "SPLINE")
							(-4 . "&") (70 . 1)
						(-4 . "AND>")
						(-4 . "<AND")
							(0 . "ELLIPSE")
							(41 . 0.0)
							(42 . 6.283185307179586)
						(-4 . "AND>")
					(-4 . "OR>")
				)
			)
			area_obj nil
		)
		(cond
			((null js)
				(setq
					pt_in (getpoint "\nGive interior point or <Enter/Right-click> for quit?: ")
					new_pl (bpoly pt_in nil '(0 0 1))
				)
				(if (eq (type new_pl) 'ENAME)
					(setq area_obj (vlax-get-property (setq ename (vlax-ename->vla-object new_pl)) "Area"))
					(setq loop nil)
				)
			)
			(T
				(setq area_obj (vlax-get-property (setq ename (vlax-ename->vla-object (ssname js 0))) "Area"))
			)
		)
		(cond
			(area_obj
				(if (zerop (getvar "USERR1")) (setvar "USERR1" (/ (getvar "VIEWSIZE") 75.0)))
				(setq nw_obj
					(vla-addMtext Space
						(vlax-3d-point (trans (getvar "VIEWCTR") 1 0))
						0.0
						(strcat
							(rtos (* area_obj 0.0001) 2 3)
							"ha \\P"
							(rtos (* area_obj 0.0002471053814) 2 2)
							"ac"
						)
					)
				)
				(mapcar
					'(lambda (pr val)
						(vlax-put nw_obj pr val)
					)
					(list 'AttachmentPoint 'Height 'DrawingDirection 'StyleName 'Layer 'Rotation 'BackgroundFill 'Color)
					(list 1 (getvar "USERR1") 5 (getvar "TEXTSTYLE") (getvar "CLAYER") 0.0 -1 256)
				)
				(setq
					ent_text (entlast)
					dxf_ent (entget ent_text)
					dxf_ent (subst (cons 90 1) (assoc 90 dxf_ent) dxf_ent)
					dxf_ent (subst (cons 63 255) (assoc 63 dxf_ent) dxf_ent)
				)
				(entmod dxf_ent)
				(while (and (setq key (grread T 4 0)) (/= (car key) 3))
					(cond
						((eq (car key) 5)
							(setq dxf_ent (subst (cons 10 (trans (cadr key) 1 0)) (assoc 10 dxf_ent) dxf_ent))
							(entmod dxf_ent)
						)
					)
				)
				(vlax-put
					(vlax-ename->vla-object (entlast))
					'TextString
					(strcat
						"{\\fArial|b0|i0|c0|p34;"
						"%<\\AcObjProp.16.2 Object(%<\\_ObjId "
						(itoa (vla-get-ObjectID ename))
						">%).Area \\f \"%lu2%pr3%ps[,ha ]%ct8[0.0001]\">%\\P"
						"%<\\AcObjProp.16.2 Object(%<\\_ObjId "
						(itoa (vla-get-ObjectID ename))
						">%).Area \\f \"%lu2%pr2%ps[,ac]%ct8[0.0002471053814]\">%"
					)
				)
			)
			(T (setq loop nil))
		)
		(princ "\nSelect a closed object or <Enter/Right-click> for a point in interior of area")
	)
	(prin1)
)
0 Likes

ronjonp
Advisor
Advisor
0 Likes

Kirillspec
Contributor
Contributor

I mean 100000 boundaries needs to be created. Thank you again for the tips about Boundary set set. It lift performance twice.

0 Likes

ronjonp
Advisor
Advisor

@Kirillspec You might also try the undocumented (bpoly (getpoint)) for a speed improvement.

0 Likes

Kirillspec
Contributor
Contributor

Yes, thanks, i’ve already tried it. It have Approximately

 the same performance in my case

0 Likes

Kirillspec
Contributor
Contributor

Thanks! This code uses bpoly. In my case It have almost the same performance as the boundary command

0 Likes

Kirillspec
Contributor
Contributor

Fantastic! Thank you very much! This is absolutely what I need!

0 Likes