- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I appologize in advance for the extension of this post, the many questions asked and the frustration that may be implicitely expressed in this post.
I am working with the Inventor API, creating an Addin for Inventor, using VB.NET.
My goal is to use the method AddFlushContraint, to create a Flush Constraint in an Assembly. I want to do this automatically, without asking any input to the user during the process.
So step by step:
The idea is to mimic the iLogic command:
Dim Fluchtend_1 As FlushConstraint
Fluchtend_1 = Constraints.AddFlush(name_constraint,
component1, entity of component1,
component2, entity of component2,
offset).Constraint
I was previously working with iLogic Rules and this worked jut fine. Unfortunately, it seems to be impossible to use in VB.NET, since there is no equivalent comand for "ThisDoc" (it is only defined within the iLogic-addin), neither for iLogicVb.Automation. Therefore it is not only possible to use the Contraints.AddFlush method shown above. This has been corroborated in various articles and Forum publications that I've read, but if someone knows a way to work around this, it would be a direct solution to my problem.
So, I have tried to use the method Inventor.AssemblyContraints.AddFlushContraint. I find the documentation in Inventor 2018 Help | Autodesk pretty bad and incomplete, inclusively giving examples with methods that don't work anymore (is there any other source of documentation for the Inventor API?). Apparently, this method uses 3 inputs (and 2 more optional, that I won't use):
AssemblyConstraints.AddFlushConstraint( EntityOne As Object, EntityTwo As Object, Offset As Variant, [BiasPointOne] As Variant, [BiasPointTwo] As Variant ) As FlushConstraint
EntityOne and EntityTwo can be of the type either a Workplane or a FaceProxy, for what I undestood. However, I am not able to access the entities (faces) that I want as Workplane or FaceProxy without further user input. When I was using the iLogic rules, I named the faces that I pretended to define contraints uppon, and I could directly access these entities, through the assigned names.
Even though I can access these entities through their names, in VB.NET, I can only assign them as Inventor.Face type (and neither as Inventor.Workplane or Inventor.FaceProxy). I've tried to use followig method, to convert Face into FaceProxy:
Dim oFaceProxy As FaceProxy = Nothing
oOcc.CreateGeometryProxy(oFace, oFaceProxy)
'The "oOcc" is the ComponentOccurrence, where the pretended entity is defined
'The "oFace" is the pretended entity, already correctly assigned as type Inventor.Face
This was a method proposed in several Forum Publications (e.g. Solved: FaceProxy to Name - Autodesk Community - Inventor). However, it doesn't seem to work for me. In every post that I saw using this method, the "oFace" is assigned as follows:
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Face")
This is the type of additional user input that I am trying to avoid. And furthermore, even though it is declared of type Inventor.Face, it is actually directly assigned as Inventor.FaceProxy (so, I don't relly understand the usage of the "oOcc.CreateGeometryProxy" as conversion method, because, in reallity, oFace is already of type FaceProxy before this implementation. Every time I've tried to use this "type conversion" with a proper entity of type Inventor.Face, I get an error.). If someone finds me a proper way to convert an Object of type Inventor.Face in Inventor.FaceProxy, my problem would be, once again, solved. Other solution would be to find a method to get an Inventor.FaceProxy object, without using the CommandManager.Pick method above.
I've tried as well to use the following procedure, developed by @BrianEkins in VB.net Find Face by face name. - Autodesk Community - Inventor:
Public Sub GetNameTest()
Dim doc As PartDocument = ThisApplication.ActiveDocument
Dim faceOrEdge As Object = GetNamedEntity(doc, "Brian")
End Sub
Public Function GetNamedEntity(doc As Inventor.Document, name As String) As Object
Dim attribMgr As AttributeManager = doc.AttributeManager
Dim objsFound As ObjectCollection
objsFound = attribMgr.FindObjects("iLogicEntityNameSet", "iLogicEntityName", name)
If objsFound.Count > 0 Then
Return(objsFound.Item(1))
Else
Return(Nothing)
End If
End Function
However, once again, I am unable to assign the output Object of GetNamedEntities(...) as Inventor.WorkPlane or Inventor.FaceProxy.
The solution I found, for now, is to run an iLogic Rule (where I've implemented the Constraints.AddFlush method) from the Inventor API, but this is naturally not a good procedure. I am trying to develop a solution as independent from iLogic as possible.
Any help is very welcome. Thanks,
António Sanches
2 Extra questions:
I've been programing in VB.NET for a while now, and I'm constantly coming across complicated problems for very simple precodures. The documentation and support for VB.NET seems to be also very poor and out of date (because Microsoft is no longer developping VB.NET...). Should I start implementing my solutions in C#? Is troubleshooting easier in C# than in VB.NET?
Is there any way to define input for external iLogic rules (in iLogic, I used to use SharedVariable) from the Inventor API?
Solved! Go to Solution.