Inventor Customization

Reply
Distinguished Contributor
TONELLAL
Posts: 140
Registered: ‎01-17-2010
Message 1 of 10 (266 Views)

bug ?

266 Views, 9 Replies
03-01-2013 06:26 AM

Hello,

I wrote a little add-in to add a workpoint at the center of mass of the part or assembly. It functions perfectly on parts, but on assembly sometimes it fucntions sometimes not : I have an error : "Unspecified error : HRESULT : 0x80004005 (E_FAIL)" when creating the workpoint. Where is the bug ?

 

Sub

WorkPointAtMassCenter()

       

'Create a workpoint at the center of mass of the active document

       

' Set a reference to the active document.

       

Dim oDoc As Inventor.Document

        oDoc = g_inventorApplication.ActiveDocument

       

Dim oCompDef AsComponentDefinition

        oCompDef = oDoc.componentdefinition

       

' Get the Center of Mass.

       

Dim oCenterOfMass As Inventor.Point

        oCenterOfMass = oCompDef.MassProperties.CenterOfMass

       

OnErrorResumeNext

       

Dim oWorkPoint As Inventor.WorkPoint

        oWorkPoint = oCompDef.WorkPoints.item("Center Of Mass")

       

If Err.Number = 0 Then oWorkPoint.Delete() 'If the workpoint already exist, delete it

       

' Create a new workpoint at the location of the center of mass.

        oWorkPoint = oCompDef.WorkPoints.AddFixed(oCenterOfMass) 'the error occurs on this line

       

' Rename the work point.

        oWorkPoint.Name ="Center Of Mass"

       

' End If

       

OnErrorGoTo 0

   

EndSub

 

Employee
yuhanzhang
Posts: 411
Registered: ‎01-06-2009
Message 2 of 10 (239 Views)

Re: bug ?

03-03-2013 11:50 PM in reply to: TONELLAL

Can you check that if it fails what the oCompDef.MassProperties.CenterOfMass really returns? Whether an initialized point it returns or not?



Rocky Zhang
Inventor API
Manufacturing Solutions
Autodesk, Inc.

Distinguished Contributor
TONELLAL
Posts: 140
Registered: ‎01-17-2010
Message 3 of 10 (231 Views)

Re: bug ?

03-04-2013 02:22 AM in reply to: yuhanzhang

After the line : oCenterOfMass = oCompDef.MassProperties.CenterOfMass

oCenterOfMass contains the right values for X, Y and Z, but  oCompDef.MassProperties.CenterOfMass is in error : "COM error : no child available".

Employee
yuhanzhang
Posts: 411
Registered: ‎01-06-2009
Message 4 of 10 (210 Views)

Re: bug ?

03-04-2013 07:37 PM in reply to: TONELLAL

This looks wierd, if the oCompDef.MassProperties.CenterOfMass returns an error, the failure should happens at the line: oCenterOfMass = oCompDef.MassProperties.CenterOfMass. But if you have the  oCenterOfMass with right value I think the AddFixed should succeed. Can you double check that which line the error really happens? And can you add below line above the  oCenterOfMass = oCompDef.MassProperties.CenterOfMass:

 

 

Dim oUpdateMassProperties As ControlDefinition
oUpdateMassProperties  = g_inventorApplication.CommandManager.ControlDefinitions("AppUpdateMassPropertiesCmd")
oUpdateMassProperties.Execute()

 The code will help to update the mass properties, so the oCompDef.MassProperties.CenterOfMass then will return correct values. Please check if it helps.

 

 



Rocky Zhang
Inventor API
Manufacturing Solutions
Autodesk, Inc.

Distinguished Contributor
TONELLAL
Posts: 140
Registered: ‎01-17-2010
Message 5 of 10 (200 Views)

Re: bug ?

03-06-2013 01:03 AM in reply to: yuhanzhang

I add the code for Massproperties update.

 

There is an error is on the line :

        oCenterOfMass = oCompDef.MassProperties.CenterOfMass

 

I've put a breakpoint on the line, with 2 spies, on oCenterOfMass and on oCompDef.MassProperties.CenterOfMass.

Before the line is executed, I have :

oCenterOfMass = nothing

oCompDef.MassProperties.CenterOfMass = <COM type> "Erreur : no child available"

oCompDef is ok.

oCompDef.MassProperties is in error : "Erreur : no child available"

After the line is executed, I have :

oCenterOfMass = Inventor.point

   x=...

   y=...

   z=...

oCompDef.MassProperties.CenterOfMass = <COM type> "Erreur : no child available"

 

 Another error on when creating the workpoint :

oWorkPoint = oCompDef.WorkPoints.AddFixed(oCenterOfMass)

oCenterOfMass is right.

oCompDef is defined and seems to be right.

 oCompDef.WorkPoints is in error : "No child available".

Employee
yuhanzhang
Posts: 411
Registered: ‎01-06-2009
Message 6 of 10 (185 Views)

Re: bug ?

03-06-2013 06:13 PM in reply to: TONELLAL

Looks like the MassProperties(oCompDef.MassProperties) does not work well there. Can you open the assembly which causes the code error, and open its iProperties dialog, and see if the Physical->General Properties->Center of Gravity has proper values? And if the Update button is enabled, click it and  save the document, then try the code with the assembly to see if it works?



Rocky Zhang
Inventor API
Manufacturing Solutions
Autodesk, Inc.

Distinguished Contributor
TONELLAL
Posts: 140
Registered: ‎01-17-2010
Message 7 of 10 (153 Views)

Re: bug ?

03-13-2013 07:35 AM in reply to: yuhanzhang

I open the assembly : the mass properties need to be updated.

Cancel the dialog box without updating.

Run the add-in: "Unspecifief error : HRESULT Exception : 0x80004005 (E_FAIL)

iProperties > mass properties are up to date, so the code to update mas properties functions. Ne need to update.

Run the add-in again : same error.

Employee
yuhanzhang
Posts: 411
Registered: ‎01-06-2009
Message 8 of 10 (145 Views)

Re: bug ?

03-15-2013 01:43 AM in reply to: TONELLAL

Is it OK for you to upload the adin and the data which can reproduce the problem so we can debug it? Please simiplify the addin as possible as you can, and don't upload any confidential data.



Rocky Zhang
Inventor API
Manufacturing Solutions
Autodesk, Inc.

Distinguished Contributor
TONELLAL
Posts: 140
Registered: ‎01-17-2010
Message 9 of 10 (140 Views)

Re: bug ?

03-15-2013 06:53 AM in reply to: yuhanzhang

I post the solution. It add a tab "Utilities" in part or seembly environment.

You can test it with standard sample files :

On a part file, no problem.

On Engine MKII, no problem.

On piping sample "Buffer prep skid.iam" you have the problem.

Employee
yuhanzhang
Posts: 411
Registered: ‎01-06-2009
Message 10 of 10 (107 Views)

Re: bug ?

03-25-2013 02:07 AM in reply to: TONELLAL

Sorry for a little late to response. I tried your project and it works fine on my machine, I don't see any problem here for the code. I used the same data as you said to test.

 

But if you still see the same problem, can you try to cast the oCompDef to PartComponentDefinition or AssemblyComponentDefinition according to the document type instead of the ComponentDefinition. Please let me if it works.

 



Rocky Zhang
Inventor API
Manufacturing Solutions
Autodesk, Inc.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube