Creating ProxyPoint and WP in Python

Creating ProxyPoint and WP in Python

michaelkolocaj
Explorer Explorer
329 Views
2 Replies
Message 1 of 3

Creating ProxyPoint and WP in Python

michaelkolocaj
Explorer
Explorer

Hi,

I´m currently working on a project to automatically configurate different parts in an assembly with constraints. While in iLogic everything works fine, I would like to build the configurator completely in python because I can combine my configuration with my AI-Features and dont need excel as communication for ilogic and python.

 

My problem:

	i = 2
	While Not oExcel.Cells.Item(i, 1).Value = ""
		Dim oOcc As ComponentOccurrence
		Dim oWP As WorkPoint
		Dim oWPProxy As WorkPointProxy
	
		oOcc = oDoc.ComponentDefinition.Occurrences.ItemByName(oExcel.Cells.Item(i, 1).Value)
		oWP = oOcc.Definition.WorkPoints(oExcel.Cells.Item(i, 2).Value)
		Call oOcc.CreateGeometryProxy(oWP, oWPProxy)
	
		oExcel.Cells.Item(i, 3).Value = (Round(oWPProxy.Point.X*100)/100).ToString()
		oExcel.Cells.Item(i, 4).Value = (Round(oWPProxy.Point.Y*100)/100).ToString()
		oExcel.Cells.Item(i, 5).Value = (Round(oWPProxy.Point.Z*100)/100).ToString()
	
		i = i + 1
	End While

I have a list with occurence-names and workpoints and want to know where those points are located in the assembly document.

 

But how can I create a ProxyPoint in python via api? Also is there another option to access the workpoints of an occurrence in python than:

oOcc.Definition.Document.ComponentDefinition.WorkPoint

'oOcc.Definition.WorkPoints' does not work because there is no object 'WorkPoints' in 'Definition'  (in ilogic it works fine)

 

import win32com.client
from win32com.client import gencache, Dispatch, constants, DispatchEx

oApp = win32com.client.Dispatch('Inventor.Application')
oApp.Visible = True
mod = gencache.EnsureModule('{D98A091D-3A0F-4C3E-B36E-61F62068D488}', 0, 1, 0)
oApp = mod.Application(oApp)
# oApp.SilentOperation = True
oDoc = oApp.ActiveDocument
oDoc = mod.AssemblyDocument(oDoc)



oOccs = oDoc.ComponentDefinition.Occurrences
# proxyWP = oDoc.ComponentDefinition.WorkPointProxy does not work

i = 0
for WP in oDoc.ComponentDefinition.WorkPoints:
i += 1
print(f'Name of Workpoint {i}: {WP.Name}')

for oOcc in oOccs:
for oWP in oOcc.Definition.Document.ComponentDefinition.WorkPoints:
print(oWP.Name)
print(oOcc.Name)
# oOcc.CreateGeometryProxy(oWP, proxyWP)
print(oWP.Point.X)
0 Likes
330 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @michaelkolocaj.  I am not familiar with Python, but I know that there is no such thing as "ProxyPoint" or "PointProxy".  The only Inventor API object similar to that is the WorkPointProxy object, which you are already creating within your first code example.

As for the oOcc.Definition.WorkPoints not working for you in Python, while it does work in iLogic...I know it would require more typing/code, but you could declare a more specific Type of component definition variable (PartComponentDefinition or AssemblyComponentDefinition), then set its value using oOcc.Definition, then use that variable to access the WorkPoints, instead of using oOcc.Definition.Document.ComponentDefinition.WorkPoints...just another option.

The WorkPointProxy object can not be found/obtained from a collection of WorkPointProxys within the ComponentDefinition of a Part, because they only exist in assemblies, and there is no WorkPointProxys type collection in the API.  In an assembly, only the assembly's own origin point, and any WorkPoints created directly within the context of the main assembly will be regular WorkPoint objects, all others that may be present in the assembly, due to other components, will be WorkPointProxy.  So, there are two ways to get a WorkPointProxy.  You can obtain it using the ComponentOccurrence.CreateGeometryProxy() method, where the second input variable gets its value set to it by that method.  If you do this, then use that proxy variable for something after that point, or add it to a collection, otherwise you will loose your reference to it.  If you just keep looping using that same variable, and never using that proxy variable for anything, you are not accomplishing anything.  You are not actually creating anything new with that method, just obtaining a reference to that geometry object within the context of the 'parent' model/coordinate space.  The other way to obtain a reference to a proxy is to select any geometry within the assembly that was not created within the assembly, such as FaceProxy, EdgeProxy, & VertexProxy of any assembly component. (Link)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

michaelkolocaj
Explorer
Explorer

Hi,

 

Explanation of what I want to accomplish:

I have created different parts with specif named WorkPoints (for example "part1" with WorkPoints "WP_Connector_1" and "WP_Connector_2"; "part2" with WorkPoints "WP_Connector_1" and "WP_Connector_2").

 

After creating an assembly with many different iterations of part1 and part2, I need to know where those WorkPoints are located in the assembly (X/Y/Z). With those coordinates, I exactly know the location and connected neighbor parts. For example, in a pipe-system I know with those points where the water will flow and try to find a better routing using an AI/Configurator.

Current work process is to run the rule and save the coordinates of the WorkPointProxy in a ExcelSheet and then read it with an external program.

 

I want to combine it in one program using python or c#, that I don't need to run the already working iLogic-rule but only the program to speed things up.

 

After switching to C# it is easier to handle objects from the API:

 

            AssemblyDocument asmDoc = default(AssemblyDocument);
            asmDoc = (AssemblyDocument)_invApp.ActiveDocument;

            ComponentOccurrences oOccs = default(ComponentOccurrences);
            oOccs = asmDoc.ComponentDefinition.Occurrences;

            Object proxyPoint;

            foreach(ComponentOccurrence oOcc in oOccs)
            {
                WorkPoints oWPs = oOcc.Definition.Document.ComponentDefinition.WorkPoints;
                foreach (WorkPoint oWP in oWPs)
                {
                    if (oWP.Name.Contains("Connector"))
                    {
                        oOcc.CreateGeometryProxy(oWP, out proxyPoint);
                        WorkPointProxy pointProxy = proxyPoint as WorkPointProxy;
                        double x = pointProxy.Point.X;
                        double y = pointProxy.Point.Y;
                        double z = pointProxy.Point.Z;
                        Console.WriteLine("X: " + x.ToString() + " Y: " + y.ToString() + " Z: " + z.ToString());

                    }
                }
            }

 

0 Likes