RangeBox for a Sketch

RangeBox for a Sketch

J.Pelfrene
Enthusiast Enthusiast
640 Views
5 Replies
Message 1 of 6

RangeBox for a Sketch

J.Pelfrene
Enthusiast
Enthusiast

Is there a method for getting the RangeBox of a Sketch in a PartDocument?

Sketch, Profile, RegionProperties, SketchBlock, ... None of these offer a RangeBox method. SketchEntity does, but that's for a single entity, not the entire sketch.

 

Thanks!

0 Likes
Accepted solutions (3)
641 Views
5 Replies
Replies (5)
Message 2 of 6

JelteDeJong
Mentor
Mentor
Accepted solution

You can make your own function. something like this:

 

Dim doc As PartDocument = ThisDoc.Document

Dim sketch As PlanarSketch = doc.ComponentDefinition.Sketches.Item(1)
Dim allMinPoints As List(Of Point2d) = sketch.
	SketchEntities.
	Cast(Of SketchEntity).
	Select(Function(e) e.RangeBox.MinPoint).
	OrderBy(Function(p) p.X).ToList()
Dim minX = allMinPoints.First().X
Dim minY = allMinPoints.OrderBy(Function(p) p.Y).First().Y

Dim allMaxPoints As List(Of Point2d) = sketch.
	SketchEntities.
	Cast(Of SketchEntity).
	Select(Function(e) e.RangeBox.MaxPoint).
	OrderBy(Function(p) p.X).ToList()
Dim maxX = allMaxPoints.Last().X
Dim maxY = allMaxPoints.OrderBy(Function(p) p.Y).Last().Y

Dim rangebox As Box2d = ThisApplication.TransientGeometry.CreateBox2d()
rangebox.MinPoint = ThisApplication.TransientGeometry.CreatePoint2d(minX, minY)
rangebox.MaxPoint = ThisApplication.TransientGeometry.CreatePoint2d(maxX, maxY)

sketch.Edit()
sketch.SketchLines.AddAsTwoPointRectangle(rangebox.MinPoint, rangebox.MaxPoint)

 Edit: I found a bug after posting and i solved it.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 6

J.Pelfrene
Enthusiast
Enthusiast

Thank you!

I thought of doing it this way too, but was afraid it would be computationally expensive. It is not!

And interesting to learn something from your code as well.

 

Cheers

0 Likes
Message 4 of 6

j_weber
Mentor
Mentor
Accepted solution

@JelteDeJong 

 

Great code.

Is it also possible to change the color of the range box to for example orange or to change the style to construction

 

 




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





0 Likes
Message 5 of 6

JelteDeJong
Mentor
Mentor
Accepted solution

you can try it like this:

Dim doc As PartDocument = ThisDoc.Document

Dim sketch As PlanarSketch = doc.ComponentDefinition.Sketches.Item(1)
Dim allMinPoints As List(Of Point2d) = sketch.
	SketchEntities.
	Cast(Of SketchEntity).
	Select(Function(e) e.RangeBox.MinPoint).
	OrderBy(Function(p) p.X).ToList()
Dim minX = allMinPoints.First().X
Dim minY = allMinPoints.OrderBy(Function(p) p.Y).First().Y

Dim allMaxPoints As List(Of Point2d) = sketch.
	SketchEntities.
	Cast(Of SketchEntity).
	Select(Function(e) e.RangeBox.MaxPoint).
	OrderBy(Function(p) p.X).ToList()
Dim maxX = allMaxPoints.Last().X
Dim maxY = allMaxPoints.OrderBy(Function(p) p.Y).Last().Y

Dim rangebox As Box2d = ThisApplication.TransientGeometry.CreateBox2d()
rangebox.MinPoint = ThisApplication.TransientGeometry.CreatePoint2d(minX, minY)
rangebox.MaxPoint = ThisApplication.TransientGeometry.CreatePoint2d(maxX, maxY)

sketch.Edit()
Dim lines = sketch.SketchLines.AddAsTwoPointRectangle(rangebox.MinPoint, rangebox.MaxPoint)

Dim red = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
For Each line As SketchLine In lines
	line.Construction = True
	line.OverrideColor = red
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 6 of 6

j_weber
Mentor
Mentor

Thanks a lot 🙂




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





0 Likes