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: 

Inventor 2022 State C# programming

5 REPLIES 5
Reply
Message 1 of 6
penzes_ferenc
976 Views, 5 Replies

Inventor 2022 State C# programming

penzes_ferenc
Explorer
Explorer

Dear Everybody.

 

I am learning Inventor programming. A big change is the state.

Would anyone write in a C # programming language that I can switch between states?

I tried to rewrite VB.net but it didn't come together.

Thanks your help.

0 Likes

Inventor 2022 State C# programming

Dear Everybody.

 

I am learning Inventor programming. A big change is the state.

Would anyone write in a C # programming language that I can switch between states?

I tried to rewrite VB.net but it didn't come together.

Thanks your help.

Labels (4)
5 REPLIES 5
Message 2 of 6
SharkDesign
in reply to: penzes_ferenc

SharkDesign
Mentor
Mentor

I don't know if you can use C programming.

There's a VBA editor and iLogic.

iLogic is BASED on VB.net but not exactly the same. 

An in depth description of what you are trying to achieve would be very useful too. 

 

Post your VB.net code and someone will have a look at why it won't work in iLogic. 

 

  Expert Elite
  Inventor Certified Professional
0 Likes

I don't know if you can use C programming.

There's a VBA editor and iLogic.

iLogic is BASED on VB.net but not exactly the same. 

An in depth description of what you are trying to achieve would be very useful too. 

 

Post your VB.net code and someone will have a look at why it won't work in iLogic. 

 

  Expert Elite
  Inventor Certified Professional
Message 3 of 6

penzes_ferenc
Explorer
Explorer

I'll be a little more specific.

I would like to select one of the ipt states from a combo box.

Insert the selected state into the assembly.

I practice programming in visual studio 2019, but I can't find anything about the states that would be in C #.

I would like to ask for an example of a C # language for state control

 

Inventor 2022 api help example that's not what I want VB.NET:

Public Sub CreateModelState()   

' Set a reference to the assembly component definintion.   

' This assumes an assembly document is open.   

Dim oAsmCompDef As AssemblyComponentDefinition    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition    

' Set a reference to the transient geometry object.  

  Dim oTG As TransientGeometry    Set oTG = ThisApplication.TransientGeometry    

' Create a matrix. A new matrix is initialized with an identity matrix.   

Dim oMatrix As Matrix    Set oMatrix = oTG.CreateMatrix    

 

' Add the first occurrence.   

Dim oOcc1 As ComponentOccurrence    

Set oOcc1 = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix)        

 

' Set the translation portion of the matrix so the    ' second part will be positioned at (3,2,1).   

Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))        

 

' Add the second occurrence.   

Dim oOcc2 As ComponentOccurrence   

Set oOcc2 = oAsmCompDef.Occurrences.Add("C:\Temp\Part2.ipt", oMatrix)        

 

' Create a new level of detail representation.   

' The new representation is automatically activated.   

 

Dim oModelState As ModelState   

Set oModelState = oAsmCompDef.ModelStates.Add("Part2Suppressed")       

 

 ' Suppress the second component in the new model state.   

' If the document "C:\Temp\Part2.ipt" is not currently referenced   

' elsewhere, it will be closed.   

Assembly_part_state.PNGoOcc2.SuppressEnd Sub     

 

 

0 Likes

I'll be a little more specific.

I would like to select one of the ipt states from a combo box.

Insert the selected state into the assembly.

I practice programming in visual studio 2019, but I can't find anything about the states that would be in C #.

I would like to ask for an example of a C # language for state control

 

Inventor 2022 api help example that's not what I want VB.NET:

Public Sub CreateModelState()   

' Set a reference to the assembly component definintion.   

' This assumes an assembly document is open.   

Dim oAsmCompDef As AssemblyComponentDefinition    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition    

' Set a reference to the transient geometry object.  

  Dim oTG As TransientGeometry    Set oTG = ThisApplication.TransientGeometry    

' Create a matrix. A new matrix is initialized with an identity matrix.   

Dim oMatrix As Matrix    Set oMatrix = oTG.CreateMatrix    

 

' Add the first occurrence.   

Dim oOcc1 As ComponentOccurrence    

Set oOcc1 = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix)        

 

' Set the translation portion of the matrix so the    ' second part will be positioned at (3,2,1).   

Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))        

 

' Add the second occurrence.   

Dim oOcc2 As ComponentOccurrence   

Set oOcc2 = oAsmCompDef.Occurrences.Add("C:\Temp\Part2.ipt", oMatrix)        

 

' Create a new level of detail representation.   

' The new representation is automatically activated.   

 

Dim oModelState As ModelState   

Set oModelState = oAsmCompDef.ModelStates.Add("Part2Suppressed")       

 

 ' Suppress the second component in the new model state.   

' If the document "C:\Temp\Part2.ipt" is not currently referenced   

' elsewhere, it will be closed.   

Assembly_part_state.PNGoOcc2.SuppressEnd Sub     

 

 

Message 4 of 6

Michael.Navara
Advisor
Advisor

I don't know if it is what you are looking for, but here is rewritten example to C#. I keep original code as comments.

The API object model  is the same for VBA, VB.NET (iLogic) and C#. Differences are only in language syntax.

 

public void CreateModelState()
{
    //Public Sub CreateModelState()
    //    ' Set a reference to the assembly component definintion.
    //    ' This assumes an assembly document is open.
    //    Dim oAsmCompDef As AssemblyComponentDefinition
    //    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    var oAsmDoc = ThisApplication.ActiveDocument as AssemblyDocument;
    var oAsmCompDef = oAsmDoc.ComponentDefinition;

    //    ' Set a reference to the transient geometry object.
    //    Dim oTG As TransientGeometry
    //    Set oTG = ThisApplication.TransientGeometry
    var oTG = ThisApplication.TransientGeometry;

    //    ' Create a matrix. A new matrix is initialized with an identity matrix.
    //    Dim oMatrix As Matrix
    //    Set oMatrix = oTG.CreateMatrix
    var oMatrix = oTG.CreateMatrix();

    //    ' Add the first occurrence.
    //    Dim oOcc1 As ComponentOccurrence
    //    Set oOcc1 = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix)
    var oOcc1 = oAsmCompDef.Occurrences.Add(@"C:\Temp\Part1.ipt", oMatrix);

    //    ' Set the translation portion of the matrix so the
    //    ' second part will be positioned at (3,2,1).
    //    Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))
    oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1));

    //    ' Add the second occurrence.
    //    Dim oOcc2 As ComponentOccurrence
    //    Set oOcc2 = oAsmCompDef.Occurrences.Add("C:\Temp\Part2.ipt", oMatrix)
    var oOcc2 = oAsmCompDef.Occurrences.Add(@"C:\Temp\Part2.ipt", oMatrix);

    //    ' Create a new level of detail representation.
    //    ' The new representation is automatically activated.
    //    Dim oModelState As ModelState
    //    Set oModelState = oAsmCompDef.ModelStates.Add("Part2Suppressed")
    var oModelState = oAsmCompDef.ModelStates.Add("Part2Suppressed");

    //    ' Suppress the second component in the new model state.
    //    ' If the document "C:\Temp\Part2.ipt" is not currently referenced
    //    ' elsewhere, it will be closed.
    oOcc2.Suppress();

    //End Sub
}

 

0 Likes

I don't know if it is what you are looking for, but here is rewritten example to C#. I keep original code as comments.

The API object model  is the same for VBA, VB.NET (iLogic) and C#. Differences are only in language syntax.

 

public void CreateModelState()
{
    //Public Sub CreateModelState()
    //    ' Set a reference to the assembly component definintion.
    //    ' This assumes an assembly document is open.
    //    Dim oAsmCompDef As AssemblyComponentDefinition
    //    Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    var oAsmDoc = ThisApplication.ActiveDocument as AssemblyDocument;
    var oAsmCompDef = oAsmDoc.ComponentDefinition;

    //    ' Set a reference to the transient geometry object.
    //    Dim oTG As TransientGeometry
    //    Set oTG = ThisApplication.TransientGeometry
    var oTG = ThisApplication.TransientGeometry;

    //    ' Create a matrix. A new matrix is initialized with an identity matrix.
    //    Dim oMatrix As Matrix
    //    Set oMatrix = oTG.CreateMatrix
    var oMatrix = oTG.CreateMatrix();

    //    ' Add the first occurrence.
    //    Dim oOcc1 As ComponentOccurrence
    //    Set oOcc1 = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix)
    var oOcc1 = oAsmCompDef.Occurrences.Add(@"C:\Temp\Part1.ipt", oMatrix);

    //    ' Set the translation portion of the matrix so the
    //    ' second part will be positioned at (3,2,1).
    //    Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1))
    oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1));

    //    ' Add the second occurrence.
    //    Dim oOcc2 As ComponentOccurrence
    //    Set oOcc2 = oAsmCompDef.Occurrences.Add("C:\Temp\Part2.ipt", oMatrix)
    var oOcc2 = oAsmCompDef.Occurrences.Add(@"C:\Temp\Part2.ipt", oMatrix);

    //    ' Create a new level of detail representation.
    //    ' The new representation is automatically activated.
    //    Dim oModelState As ModelState
    //    Set oModelState = oAsmCompDef.ModelStates.Add("Part2Suppressed")
    var oModelState = oAsmCompDef.ModelStates.Add("Part2Suppressed");

    //    ' Suppress the second component in the new model state.
    //    ' If the document "C:\Temp\Part2.ipt" is not currently referenced
    //    ' elsewhere, it will be closed.
    oOcc2.Suppress();

    //End Sub
}

 

Message 5 of 6

penzes_ferenc
Explorer
Explorer

Thank's your help michael.navara.

I am learning how to program Inventor and I'm looking at Inventor / Help / Api.I cannot find many programming examples of this new state.
First, I want to learn how to create a state in ipt. For example, I want to create a cylinder and a cube. Then create separate states for them.

Inventor_2022_state_cylinder.PNGInventor_2022_state_master.PNG

And I want to put the cube or the cylinder in the assembly.

Inventor_2022_assembly_state.PNG

I don't know how I could get started.

I would ask for help in this. With an example or a website link ..

 

 

 

0 Likes

Thank's your help michael.navara.

I am learning how to program Inventor and I'm looking at Inventor / Help / Api.I cannot find many programming examples of this new state.
First, I want to learn how to create a state in ipt. For example, I want to create a cylinder and a cube. Then create separate states for them.

Inventor_2022_state_cylinder.PNGInventor_2022_state_master.PNG

And I want to put the cube or the cylinder in the assembly.

Inventor_2022_assembly_state.PNG

I don't know how I could get started.

I would ask for help in this. With an example or a website link ..

 

 

 

Message 6 of 6
JelteDeJong
in reply to: penzes_ferenc

JelteDeJong
Mentor
Mentor

not sure if this helps you a lot but maybe you find this blogpost useful

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

not sure if this helps you a lot but maybe you find this blogpost useful

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

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

Post to forums  

Autodesk Design & Make Report