View Sketch on Creation | VBA

View Sketch on Creation | VBA

Anonymous
Not applicable
505 Views
2 Replies
Message 1 of 3

View Sketch on Creation | VBA

Anonymous
Not applicable

.

 

[newbie alert]

 

I've been using Inv since R5.3, approx 11 years.

 

However, I've never doen any VBA programming within Inv and I'm just starting to get my head around this task. I have done a bit of VBA in MS Word & Excel, but this is a little different.

 

I want to create a Sketch. I want the user to be able to chose by selecting either in the browser or the face/workplane as you would when creating features in Inv. And I want the sketch to stay in Edit so the user can create their own sketch features.

 

I've found some code snippets to create a sketch and another to edit an existing sketch, which I could utilise.

 

However, I can't seem to find anything that will change the view so the User will be looking directly at the sketch to make sketching easier.

 

Inv's Options, Sketchs are already set to Look at sketch plane on Sketch Creation Man Frustrated

 

I realise I've opened a Pandora's Box of Worms - I don't mix my metaphors, I blend them Man Happy but to learn something you have to start somewhere.

 

I've tried searching this forum and the WWW but to no avail.

 

TIA

cheerz

 

0 Likes
506 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Hello,

 

There is my code (hope you do not mind its in ILogic not pure VB).

 

The code create new part (im still searching how to create sheet metal part too).

Then let you pick plane what you want.

Create sketch.

 

' Connect to a running instance of Inventor.
Dim invApp As Inventor.Application 
invApp = System.Runtime.InteropServices.Marshal.GetActiveObject _ 
                                            ("Inventor.Application") 

' Get the Documents collection.
Dim docs As Inventor.Documents = invApp.Documents 

' Create a new part document.
Dim partDoc As Inventor.PartDocument 
partDoc = docs.Add(Inventor.DocumentTypeEnum.kPartDocumentObject) 

' Get the component definition.
Dim partDef As Inventor.PartComponentDefinition 
partDef = partDoc.ComponentDefinition 

' Get the X-Y work plane. 
Dim xyPlane As Inventor.WorkPlane = partDef.WorkPlanes.Item(3) 
' Get the X-Z work plane.
Dim xzPlane As Inventor.WorkPlane = partDef.WorkPlanes.Item(2) 
' Get the Z-Y work plane. 
Dim zyPlane As Inventor.WorkPlane = partDef.WorkPlanes.Item(1) 

' Select work plane. 
Dim n As Integer
'n = InputBox("Vyberte pracovní rovinu" & " " & "XY = 3" & " " & "XZ = 2" & " " & "ZY = 1","iLogic Work Plane","")
n = InputBox ("Vyberte pracovní rovinu: " & Name _
& vbLf & "XY = 3" & ShortName _
& vbLf & "XZ = 2" & Folder_Location _
& vbLf & "ZY = 1" & CurFileName, "iLogic Work Plane")

' Create a new sketch.
Dim Sketch As Inventor.PlanarSketch 
Sketch = partDef.Sketches.Add(partDef.WorkPlanes.Item(n), False)

 There is small problem if I  change / delete useless "ShortName" "Folder_Location" and "CurFileName" rule stop works.

 

My own question : Is it possible to create directly sheet metal part?

 

 

Hope it helps

0 Likes
Message 3 of 3

Curtis_Waguespack
Consultant
Consultant

Hi duncan,

 

Here is a quick iLogic example that creates a sketch on a programatcally selected face and then sets the sketch active for edits, and looks at the sketch. Hopefully you can use this example to get closer to what you're after.

 

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

 

 

' Set a reference to part file
Dim oDoc As PartDocument 
oDoc = ThisApplication.ActiveDocument 
' Set a reference to the part component definition. 
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition
    
'Get the first face of the model.  This sample assumes a simple
' model where at least the first face is a plane.  (A box is a good
' test case.)
Dim oFace As Face
oFace = oCompDef.SurfaceBodies.Item(1).Faces.Item(1)

'Create a new sketch.  
Dim oSketch As PlanarSketch
'True projects geometry, False will not
oSketch = oCompDef.Sketches.Add(oFace, True)         
   
'edit the sketch
oSketch.Edit  

'select the sketch  
oDoc.SelectSet.Select(oSketch)   

'look at the sketch
Dim oControlDef As ControlDefinition
oControlDef = ThisApplication.CommandManager. _
ControlDefinitions.Item("AppLookAtCmd") 
oControlDef.Execute

 

EESignature

0 Likes