Find First Sketch and WorkPlane

Find First Sketch and WorkPlane

cadman777
Advisor Advisor
957 Views
8 Replies
Message 1 of 9

Find First Sketch and WorkPlane

cadman777
Advisor
Advisor

Hi,

I have an idea I want to test out.

I want to use iLogic to find the first sketch in an ipt file, and then find the workplane that sketch is on.

Then I want to make drawing views in an idw file, the first view being a birdseye view that is perpendicular to that workplane.

Has anybody written a rule like this before?

Thanx...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Accepted solutions (2)
958 Views
8 Replies
Replies (8)
Message 2 of 9

Curtis_Waguespack
Consultant
Consultant

Hi @cadman777 

 

Here is a quick example.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition

Dim oSketch As PlanarSketch
oSketch = oDef.Sketches.Item(1)

oPlane = oSketch.PlanarEntity.name

Dim oOrientation as ViewOrientationTypeEnum 
If oPlane = "XY Plane" Then	
	oOrientation = ViewOrientationTypeEnum.kFrontViewOrientation
ElseIf oPlane = "XZ Plane" Then	
	oOrientation = ViewOrientationTypeEnum.kTopViewOrientation
ElseIf oPlane = "YZ Plane" Then	
	oOrientation = ViewOrientationTypeEnum.kLeftViewOrientation
End If

oNewDrawing = ThisDoc.ChangeExtension(".idw")

oTemplateFolder = ThisApplication.FileOptions.TemplatesPath
oTemplate = oTemplateFolder & "Standard.idw"

Dim oDrawingDoc As DrawingDocument 
oDrawingDoc = ThisApplication.Documents.Add _
(DocumentTypeEnum.kDrawingDocumentObject, oTemplate, True)

oDrawingDoc.Activate()
Dim oSheet As Sheet 
oSheet = oDrawingDoc.Sheets.Item(1)

Dim oPoint As Point2d
oPoint = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)

Dim oView As DrawingView
oView = oSheet.DrawingViews.AddBaseView(oDoc, oPoint, 1, oOrientation, _
	DrawingViewStyleEnum.kShadedDrawingViewStyle)

 

EESignature

0 Likes
Message 3 of 9

Curtis_Waguespack
Consultant
Consultant
Accepted solution

or this if incase the plane is not an origin plane

 

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition

Dim oSketch As PlanarSketch
oSketch = oDef.Sketches.Item(1)

Dim oPlane As WorkPlane
oPlane = oSketch.PlanarEntity

oDoc.SelectSet.Clear
oDoc.SelectSet.Select(oPlane)

ThisApplication.CommandManager.ControlDefinitions("AppLookAtCmd").Execute

Dim oOrientation As ViewOrientationTypeEnum
oOrientation = ViewOrientationTypeEnum.kCurrentViewOrientation

oNewDrawing = ThisDoc.ChangeExtension(".idw")

oTemplateFolder = ThisApplication.FileOptions.TemplatesPath
oTemplate = oTemplateFolder & "Standard.idw"

Dim oDrawingDoc As DrawingDocument 
oDrawingDoc = ThisApplication.Documents.Add _
(DocumentTypeEnum.kDrawingDocumentObject, oTemplate, True)

oDrawingDoc.Activate()
Dim oSheet As Sheet 
oSheet = oDrawingDoc.Sheets.Item(1)

Dim oPoint As Point2d
oPoint = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)

Dim oView As DrawingView
oView = oSheet.DrawingViews.AddBaseView(oDoc, oPoint, 1, oOrientation, _
	DrawingViewStyleEnum.kShadedDrawingViewStyle)

 

EESignature

0 Likes
Message 4 of 9

Curtis_Waguespack
Consultant
Consultant
Accepted solution

And this if you wanted to add projected views from the baseview

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition

Dim oSketch As PlanarSketch
oSketch = oDef.Sketches.Item(1)

Dim oPlane As WorkPlane
oPlane = oSketch.PlanarEntity

oDoc.SelectSet.Clear
oDoc.SelectSet.Select(oPlane)

ThisApplication.CommandManager.ControlDefinitions("AppLookAtCmd").Execute

Dim oOrientation As ViewOrientationTypeEnum
oOrientation = ViewOrientationTypeEnum.kCurrentViewOrientation

oNewDrawing = ThisDoc.ChangeExtension(".idw")

oTemplateFolder = ThisApplication.FileOptions.TemplatesPath
oTemplate = oTemplateFolder & "Standard.idw"

Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.Documents.Add _
(DocumentTypeEnum.kDrawingDocumentObject, oTemplate, True)

oDrawingDoc.Activate()
Dim oSheet As Sheet
oSheet = oDrawingDoc.Sheets.Item(1)

Dim oPoint As Point2d
oPoint = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)

Dim oView As DrawingView
oView = oSheet.DrawingViews.AddBaseView(oDoc, oPoint, 1, oOrientation, _
DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)

oPoint = ThisApplication.TransientGeometry.CreatePoint2d(20, 10)

oSheet.DrawingViews.AddProjectedView(oView, oPoint, _
DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)

oPoint = ThisApplication.TransientGeometry.CreatePoint2d(10, 20)

oSheet.DrawingViews.AddProjectedView(oView, oPoint, _
DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)

oPoint = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)

oSheet.DrawingViews.AddProjectedView(oView, oPoint, _
DrawingViewStyleEnum.kShadedDrawingViewStyle)

EESignature

0 Likes
Message 5 of 9

cadman777
Advisor
Advisor

Ya know Curtis, you're the best!

I'm going to try them tomorrow and get back to you.

Cheers!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 6 of 9

Zachary.BeasonD97A7
Contributor
Contributor

I went down this path at one point and it didn't work out the way I wanted. If you're only working with your own parts you might be fine but I have half a dozen engineers each with their own bad habits and poor practices. Starting with the sketch workplane resulted in prints that weren't very standardized depending on who designed the part. I ended up using a range box to find the longest axis of the part to determine view orientation. Then second longest axis to determine whether or not it needed to be rotated 90°. That method gave me more consistent results. 

0 Likes
Message 7 of 9

cadman777
Advisor
Advisor

Thanx for the tip Zac.

My problem is, I can't write code like Curtis or the others in here.

I always struggle with it b/c I don't have the library of 'words' in my brain, and too much else is competing for 'RAM' and drive space. Too bad I can't get an upgrade in grey matter!

Your method sounds good.

My method is for me alone, and all of my parts are:

1. CC parts w/the profile on the first sketch, the first sketch on the Origin x-y plane, and the z-axis going up, meaning unmodified CC parts (easy to use Curtis' rule),

2. CC parts w/the profile on any workplane anywere in the part (usually from a derived master sketch file) (easy to use Curtis' rule),

3. Sheetmetal parts with the first sketch on an OriginPlane or on a work-plane (difficult to determine which view is the Profile view, so Curtis' rule won't work most of the time),

4. Purchase parts that came from STEP files (mostly) off the Internet, meaning: no sketch at all in the file (impossible to use Curtis' rule).

But since #1 & #2 comprise about 90% of my parts, Curtis' rule would work well if I can compile a lot of other code to get it to do that; and since #4 comprises less than 1% of my parts, it doesn't matter that I have to make views manually; Same with #3, even though it would be nice to have a method like you use for them.

Anyway, I sure wish I had the rule making skill that some of you guys have!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 8 of 9

cadman777
Advisor
Advisor

Curtis, you 2nd and 3rd rule worked great in Inventor 2010!

Your first rule failed, and I'm trying to figure out why.

But it really doesn't matter, b/c your 2nd rule works with all parts, regardless of the Plane the first sketch sits on.

Actually, your 3rd rule is best of all, except I need to modify it to do other things, which I'm currently trying to get my head back into.

Anyway, thanx a lot for getting me started!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 9 of 9

cadman777
Advisor
Advisor

I finally got time to work on this to get it the way I want.

The problem I ran into is, it only works on parts that have a WorkPlane and Sketch created in the part.

Anything Derived doesn't work.

Do you have any code examples that find the base sketch and create the WorkPlane and work off of that?

It's beginning to look like @Zachary.BeasonD97A7's method may be a better way to do this...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes