Inventor Customization

Reply
Distinguished Contributor
pkquat
Posts: 2,530
Registered: ‎02-03-2004
Message 1 of 4 (146 Views)

IV10Sp3a How do I FillRegion a Rectangle

146 Views, 3 Replies
06-28-2007 12:53 PM
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
*Sanjay Ramaswamy \(Autodesk\)
Message 2 of 4 (146 Views)

Re: IV10Sp3a How do I FillRegion a Rectangle

06-28-2007 02:48 PM in reply to: pkquat
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
Distinguished Contributor
pkquat
Posts: 2,530
Registered: ‎02-03-2004
Message 3 of 4 (146 Views)

Re: IV10Sp3a How do I FillRegion a Rectangle

06-28-2007 03:22 PM in reply to: pkquat
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
Distinguished Contributor
guyh
Posts: 366
Registered: ‎12-11-2007
Message 4 of 4 (96 Views)

Re: IV10Sp3a How do I FillRegion a Rectangle

07-03-2011 09:18 AM in reply to: pkquat

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube