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!
Solved! Go to Solution.
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!
Solved! Go to Solution.
Solved by JelteDeJong. Go to Solution.
Solved by j_weber. Go to Solution.
Solved by JelteDeJong. Go to 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.
Blog: hjalte.nl - github.com
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.
Blog: hjalte.nl - github.com
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
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
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
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
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.
Blog: hjalte.nl - github.com
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.
Blog: hjalte.nl - github.com
Thanks a lot 🙂
Thanks a lot 🙂
Can't find what you're looking for? Ask the community or share your knowledge.