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: 

Add ifeature to workplane instead of face

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
CadUser46
711 Views, 6 Replies

Add ifeature to workplane instead of face

Im looking at the ifeature example in the help but i need to create an iFeature on the XY plane instead of a face.

 

From example:

Dim oFace As Face: Set oFace = oPartDoc.SelectSet.Item(1)

 

Looking through the forum in think i need to reference the work plane as a planar entity but im struggling with the wording.

 

The direction i was heading was:

Dim oPlane As WorkPlane: Set oPlane = oPartDoc.ComponentDefinition.WorkPlanes.Item("XY Plane")

 

Then further down in the code

                Dim oPlaneInput As iFeatureSketchPlaneInput
                Set oPlaneInput = oInput
                oPlaneInput.PlaneInput = oPlane 'Previoulsy was oFace


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
6 REPLIES 6
Message 2 of 7

Hi CadUser46,

 

Here is a quick example that should work for you  (just change the path to the iFeature").

 

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 XY work plane. 
Dim xyPlane As Inventor.WorkPlane 
xyPlane = oCompDef.WorkPlanes.Item(3) 

'select the work plane 
oDoc.SelectSet.Select(xyPlane)

'look at the work plane 
Dim oControlDef As ControlDefinition
oControlDef = ThisApplication.CommandManager. _
ControlDefinitions.Item("AppLookAtCmd")
oControlDef.Execute 'reference the part features collection Dim oFeatures As PartFeatures oFeatures = oCompDef.Features 'create an iFeatureDefinition object. Dim oiFeatureDef As iFeatureDefinition oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition( _ "C:\Temp\End_mill_curved.ide") ' Set the input. Dim oInput As iFeatureInput For Each oInput In oiFeatureDef.iFeatureInputs Dim oParamInput As iFeatureParameterInput Select Case oInput.Name Case "Sketch Plane" Dim oPlaneInput As iFeatureSketchPlaneInput oPlaneInput = oInput oPlaneInput.PlaneInput = xyPlane Case "Diameter" oParamInput = oInput oParamInput.Expression = "1 in" Case "Depth" oParamInput = oInput oParamInput.Expression = "0.5 in" End Select Next ' Create the iFeature. Dim oiFeature As iFeature oiFeature = oFeatures.iFeatures.Add(oiFeatureDef)

 

Message 3 of 7

Curtis.  Thanks for the quick reply but its not working for me.  Once i convert the .net to vba

i get the 'Object doesnt support this property or method' error when it gets to the odoc.select set line. What am i missing?

 

 

Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument

' Set a reference to the part component definition.

Dim oCompDef As PartComponentDefinition Set oCompDef = oDoc.ComponentDefinition

 

'get the XY work plane. Dim xyPlane As Inventor.WorkPlane

Set xyPlane = oCompDef.WorkPlanes.Item("XY Plane")

 

'select the work plane

oDoc.SelectSet.Select (xyPlane)

 

 

 

 

 

Meanwhile i had updated my original code as below but doing it this way i get a type mismatch error at the same point

 

 

Public Sub PlaceMyiFeature()

    'Get the part document.    

Dim oPartDoc As PartDocument: Set oPartDoc = ThisApplication.ActiveDocument        

 

'Get the XY Front plane    

Dim oPlane As WorkPlane: Set oPlane = oPartDoc.ComponentDefinition.WorkPlanes.Item("XY Plane")

       

'Select the work plane    

Dim mySelect As SelectSet

Set mySelect = oPartDoc.SelectSet.Select(oPlane)        

 

'Reference the part features collection    

Dim oFeatures As PartFeatures: Set oFeatures = oPartDoc.ComponentDefinition.Features        

 

'Create an iFeatureDefinition object.    

Dim oiFeatureDef As iFeatureDefinition    

Set oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition("C:\Temp\iFeatureTEST.ide")        

 

'Set the input.    

Dim oInput As iFeatureInput    

For Each oInput In oiFeatureDef.iFeatureInputs        

Dim oParamInput As iFeatureParameterInput        

Select Case oInput.Name            

Case "Sketch Plane"                

Dim oPlaneInput As iFeatureSketchPlaneInput                

Set oPlaneInput = oInput                

oPlaneInput.PlaneInput = oPlane        

End Select    

Next        

 

' Create the iFeature.    

Dim oiFeature As iFeature    

Set oiFeature = oFeatures.iFeatures.Add(oiFeatureDef) End Sub

 

 

 

PS:  How do you get your source code to display like that in the forum post?  I tried just searching the FAQs and boards before replying but cant see anything.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 4 of 7

Hi CadUser46,

 

I had a quick look at this, and I think all I changed was where you had this:

 

'Select the work plane    
Dim mySelect As SelectSet
Set mySelect = oPartDoc.SelectSet.Select(oPlane) 

 

I changed it to this:


'Select the work plane
Call oPartDoc.SelectSet.Select(oPlane)

 

But it occurred to me you don't actually need the lines selecting the plane at all. I had it in my iLogic rule, as I was re-using some other code that was intended to change the view and "look at" the feature once created. 

 

As for placing the code in the code window, you can use the little C button as shown to open a window into which to paste your code:

Autodesk Forum Insert Code Window.png

 

 

 

Below, is your full code that I had working from the VBA editor.

 

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

 

 

Public Sub PlaceMyiFeature()

'Get the part document.
Dim oPartDoc As PartDocument: Set oPartDoc = ThisApplication.ActiveDocument

'Get the XY Front plane
Dim oPlane As WorkPlane: Set oPlane = oPartDoc.ComponentDefinition.WorkPlanes.Item("XY Plane")
 
'Reference the part features collection
Dim oFeatures As PartFeatures: Set oFeatures = oPartDoc.ComponentDefinition.Features

'Create an iFeatureDefinition object.
Dim oiFeatureDef As iFeatureDefinition
Set oiFeatureDef = oFeatures.iFeatures.CreateiFeatureDefinition("C:\Temp\iFeatureTEST.ide")

'Set the input.
Dim oInput As iFeatureInput
For Each oInput In oiFeatureDef.iFeatureInputs
    Dim oParamInput As iFeatureParameterInput
    Select Case oInput.Name
        Case "Sketch Plane"
        Dim oPlaneInput As iFeatureSketchPlaneInput
        Set oPlaneInput = oInput
        oPlaneInput.PlaneInput = oPlane
    End Select
Next

' Create the iFeature.
Dim oiFeature As iFeature
Set oiFeature = oFeatures.iFeatures.Add(oiFeatureDef)
End Sub

 

Message 5 of 7

Curtis. Its now resorted back to an error i had earlier but didnt persue until i got this fixed.  It fails at the 'Set oiFeature' line where im referencing my iFeatureTest.ide.

 

I tested one of the default ifeatures using a UNC path and the code works fine so im inclined to think its something about my ifeature.  Can you take a look and see im not missing something obvious.  I have attached the ifeature. 

 

Some background on this.  Im trying to create geometry from nothing using a series of ifeatures as opposed to cutting something out of existing model geometry.  So from a blank file, run the macro, insert ifeatureTest.ide.

 

 

Also how do you know when to use call versus not using it?

 


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 6 of 7
CadUser46
in reply to: CadUser46

Curtis, i figured it out.  in the ifeature the sketch plane inherited the default name 'Sketch Plane1'.  In the select case statement it was looking for 'Sketch Plane'.

 

I think i can begin to make some progress from here.  Thanks.

 

PS:  Keep up the blog.  I think i have read it front to back 10 times over.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
Message 7 of 7
ChristinaForest
in reply to: CadUser46

anybody have a ifeatures and part with ilogic code in for exemple???

 

Thanks for your help!

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

Post to forums  

Autodesk Design & Make Report