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: 

IV10Sp3a How do I FillRegion a Rectangle

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
371 Views, 3 Replies

IV10Sp3a How do I FillRegion a Rectangle

Below is part of AD's sample macro for SketchFillRegion with my modifications for a Rectangle. I thought this would be simple since I don't think I need to profile it. Or do I somehow need to profile each line and add? I have tried oRect in place of oCollection for oSketch.SketchFillRegions.Add(???)

Public Sub DrawingSketchFill()
' Set a reference to the active document. This assumes it
' is a drawing document.
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

' Create a sketch on the active sheet
Dim oSketch As DrawingSketch
Set oSketch = oDoc.ActiveSheet.Sketches.Add

' Put the sketch in edit mode
oSketch.Edit

' Set a reference to the transient geometry object.
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

' Draw a circle in the sketch.
'Dim oCircle1 As SketchCircle
'Set oCircle1 = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(10, 30), 2)
Dim oRect1 As SketchEntitiesEnumerator
Set oRect1 = oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(1.27, 24.765), oTG.CreatePoint2d(6.35, 26.67))

' Create a collection and add the circle.
Dim oCollection1 As ObjectCollection
Set oCollection1 = ThisApplication.TransientObjects.CreateObjectCollection
oCollection1.Add oRect1

' Create a profile from the first circle
'Dim oProfile1 As Profile
'Set oProfile1 = oSketch.Profiles.AddForSolid(False, oCollection1)

' Create a fill region based on the layer color.
Call oSketch.SketchFillRegions.Add(oCollection1)

Pete
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

Yes, you must create a profile of the region that you intend to fill. Here
is the modified code:

Public Sub DrawingSketchFill()
' Set a reference to the active document. This assumes it
' is a drawing document.
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

' Create a sketch on the active sheet
Dim oSketch As DrawingSketch
Set oSketch = oDoc.ActiveSheet.Sketches.Add

' Put the sketch in edit mode
oSketch.Edit

' Set a reference to the transient geometry object.
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

' Draw a circle in the sketch.
'Dim oCircle1 As SketchCircle
'Set oCircle1 =
oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(10, 30), 2)
Dim oRect1 As SketchEntitiesEnumerator
Set oRect1 =
oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(1.27, 24.765),
oTG.CreatePoint2d(6.35, 26.67))

' Create a collection and add the entities of the rectangle.
Dim oCollection1 As ObjectCollection
Set oCollection1 =
ThisApplication.TransientObjects.CreateObjectCollection

Dim oSketchEntity As SketchEntity
For Each oSketchEntity In oRect1
oCollection1.Add oSketchEntity
Next

' Create a profile from the rectangle
Dim oProfile1 As Profile
Set oProfile1 = oSketch.Profiles.AddForSolid(False, oCollection1)

' Create a fill region based on the layer color.
Call oSketch.SketchFillRegions.Add(oProfile1)
End Sub

Sanjay-

wrote in message news:5642153@discussion.autodesk.com...
Below is part of AD's sample macro for SketchFillRegion with my
modifications for a Rectangle. I thought this would be simple since I don't
think I need to profile it. Or do I somehow need to profile each line and
add? I have tried oRect in place of oCollection for
oSketch.SketchFillRegions.Add(???)

Public Sub DrawingSketchFill()
' Set a reference to the active document. This assumes it
' is a drawing document.
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

' Create a sketch on the active sheet
Dim oSketch As DrawingSketch
Set oSketch = oDoc.ActiveSheet.Sketches.Add

' Put the sketch in edit mode
oSketch.Edit

' Set a reference to the transient geometry object.
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

' Draw a circle in the sketch.
'Dim oCircle1 As SketchCircle
'Set oCircle1 =
oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(10, 30), 2)
Dim oRect1 As SketchEntitiesEnumerator
Set oRect1 =
oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(1.27, 24.765),
oTG.CreatePoint2d(6.35, 26.67))

' Create a collection and add the circle.
Dim oCollection1 As ObjectCollection
Set oCollection1 =
ThisApplication.TransientObjects.CreateObjectCollection
oCollection1.Add oRect1

' Create a profile from the first circle
'Dim oProfile1 As Profile
'Set oProfile1 = oSketch.Profiles.AddForSolid(False, oCollection1)

' Create a fill region based on the layer color.
Call oSketch.SketchFillRegions.Add(oCollection1)

Pete
Message 3 of 4
Anonymous
in reply to: Anonymous

Ahh. I had the profile command in there, but couldn't get it to recognized the lines of the rectrangle. I wasn't sure if they were treated as individual or not.

These were the lines I was looking for.

Dim oSketchEntity As SketchEntity
For Each oSketchEntity In oRect1
oCollection1.Add oSketchEntity
Next

A circle and a rectangle would be a good chage to the sample file.

Also the Help wording sounded like the profile was needed for curved surfaces (only).

Thanks again.

Pete
Message 4 of 4
guyh
in reply to: Anonymous

Hi,

 

I'm trying to find a way to use ilogic to semi-auto fill profiles in my drawing.  I have found this thread but I can not get anything to work with 2011 no doubt due to the age of the code.  Can anybody help with an update?

 

thanks

AutoCADM 2011 SP2
Inventor Pro 2011 SP2

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

Post to forums  

Autodesk Design & Make Report