Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RangeBox for a Sketch

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
J.Pelfrene
441 Views, 5 Replies

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

RangeBox for a Sketch

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!

5 REPLIES 5
Message 2 of 6
JelteDeJong
in reply to: J.Pelfrene

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

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
in reply to: JelteDeJong

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

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

Message 4 of 6
j_weber
in reply to: J.Pelfrene

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

@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





Message 5 of 6
JelteDeJong
in reply to: j_weber

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

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
in reply to: J.Pelfrene

j_weber
Mentor
Mentor

Thanks a lot 🙂




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





0 Likes

Thanks a lot 🙂




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





Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report