IV10Sp3a How do I FillRegion a Rectangle

IV10Sp3a How do I FillRegion a Rectangle

Anonymous
Not applicable
601 Views
3 Replies
Message 1 of 4

IV10Sp3a How do I FillRegion a Rectangle

Anonymous
Not applicable
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
0 Likes
602 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
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
0 Likes
Message 3 of 4

Anonymous
Not applicable
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
0 Likes
Message 4 of 4

Anonymous
Not applicable

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

0 Likes