Turn off Center of Gravity by code

Turn off Center of Gravity by code

NachoShaw
Advisor Advisor
2,332 Views
21 Replies
Message 1 of 22

Turn off Center of Gravity by code

NachoShaw
Advisor
Advisor

Hi

 

I can turn off all planes and sketches which is great but, some assemblies get saved and closed with the COG turned on. As i have a completely automated process going on for many assemblies, how can i turn off the COG function by code? Couldnt find anything in the API.

 

COG1.JPG

 

COG2.JPG

 

 

Thanks

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Accepted solutions (1)
2,333 Views
21 Replies
Replies (21)
Message 2 of 22

ekinsb
Alumni
Alumni
Accepted solution

You're correct that there isn't a direct API to control the visibility of the Center of Gravity symbol.  However, I did find a workaround.  This only works for the currently active document.  It finds the Center of Gravity command and checks its "Pressed" state.  If it's pressed then that means the Center of Gravity button is pressed in the UI and the Center of Gravity is visible.  If this is the case, it calls Execute on the command, which will toggle it's state, in this case turning off the display.

 

Public Sub TurnOffCofG()
    Dim cmd As ButtonDefinition
    Set cmd = ThisApplication.CommandManager.ControlDefinitions.Item("AppCenterOfGravityCmd")
    
    If cmd.Pressed Then
        cmd.Execute
    End If
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 22

NachoShaw
Advisor
Advisor

Hi Brian

 

Thanks for the reply. I had literally found nearly the same. I made a routine that called the command and was working on how to find if the ribbon button had been pressed.

 

Thanks for the code 🙂

 

 

Regards

 

Nigel

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 4 of 22

salariua
Mentor
Mentor

Brian,

 

We really need your help now. I know you mentioned this only works with current document but can you have another look and see if we can transverse the assembly and all the leaf components.

 

I need to try and fix this bugs with your code.

 

Here is the main article describing our issue

https://knowledge.autodesk.com/support/inventor-products/troubleshooting/caas/sfdcarticles/sfdcartic...

 

But it’s been reported in several other places

https://knowledge.autodesk.com/support/inventor-products/troubleshooting/caas/sfdcarticles/sfdcartic...

 

Thank You.

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
0 Likes
Message 5 of 22

NachoShaw
Advisor
Advisor

Hi

 

I haven't tried it but.... Have you tried traversing through the assembly and opening the parts (invisible if the function works) and turning the CoG of for each part?

 

I may give it a go tomorrow if I get time

 

 

Cheers

 

Nacho

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 6 of 22

salariua
Mentor
Mentor

Nacho,

 

I did give it a try but I didn't manage to get the code right. Would appreciate the help if you can.

 

 

 

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
0 Likes
Message 7 of 22

NachoShaw
Advisor
Advisor

Hi

 

If you can either post or message me your current code / project, it will speed up the process of me starting from scratch. If its a vb project, message me and I will send you my email address privately

 

 

Cheers

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 8 of 22

ekinsb
Alumni
Alumni

I started looking at this but I must be missing something because I can't get the COG symbols from a part to display in the assembly.  Can you tell me what I'm doing wrong or post a simple assembly that has the problem?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 9 of 22

Owner2229
Advisor
Advisor

Hey, even thought (as Brian said) the COGs of sub-parts are not visible in assy, there might be cases where you want to turn it off for all sub-parts without going through each of them manually, so if that's what you've had in mind, you can try this:

 

(iLogic)

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim cmd As ButtonDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("AppCenterOfGravityCmd")
If cmd.Pressed Then cmd.Execute
For Each aDoc As Document In oDoc.AllReferencedDocuments
     Dim bDoc As Document = ThisApplication.Documents.Open(aDoc.FullFileName, False)
     Dim cmd As ButtonDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("AppCenterOfGravityCmd")
     If cmd.Pressed Then cmd.Execute
     bDoc.Save()
     bDoc.Close()     
Next
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 10 of 22

salariua
Mentor
Mentor

Mike, Brian, and Nacho,

 

Thank you for your help and suggestions.

 

I can't share this model but I did manage to make a screencast. As you will see COG features hide the model and I think I am safe in sharing this video with the public :))

 

http://autode.sk/2kjEqGI

 

I have been asked about this more than once and I had a smaller assembly around which I hope I can share. Let me see if I can find that.

 

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
0 Likes
Message 11 of 22

salariua
Mentor
Mentor

Found it, cleaned the file so we are safe.

 

My recommendation to the client was to demote/promote components and remove this corrupted file from context but as per my previous post video that’s not always possible.

 

Please give this asm a try guys.

 

 

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
0 Likes
Message 12 of 22

Owner2229
Advisor
Advisor

Sorry, my mistake. The variable "cmd" was defined twice. Here's the corrected version:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim cmd As ButtonDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("AppCenterOfGravityCmd")
If cmd.Pressed Then cmd.Execute
For Each aDoc As Document In oDoc.AllReferencedDocuments
     Dim bDoc As Document = ThisApplication.Documents.Open(aDoc.FullFileName, False)
     cmd = ThisApplication.CommandManager.ControlDefinitions.Item("AppCenterOfGravityCmd")
     If cmd.Pressed Then cmd.Execute
     bDoc.Save()
     bDoc.Close()
Next

 

...

 

I've just opened your assembly and I see the COG actually isn't in the part, it's in the assembly...

There're 3 COGs in the assembly (one for each part) and they're stored in the assembly, yet tied to the part.

Whatever new part you add to the assembly will follow this behavior, so it must be something in the assembly causing this to happen.

I'll have to examine how this was even created.

 

Anyway, this code won't be any use for this.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 13 of 22

NachoShaw
Advisor
Advisor

Hi

 

First, your ASM looks for the files

 

Box.ipt

FACE PLATE.ipt

GIB PLATE.ipt

 

so I can only assume it refers to 1, 2, 3 respectively.

 

Second, there is something going on with your Assy. I cant even turn off the visibility of a part. If I create a new Assy and place the same parts, I don't get any CoG per part and visibility works fine.

 

In an assembly, the CoG should only show you the Assembly level CoG and not the parts. when you got to part level, you can show CoG for that part.

 

Don't know whats going on with your specific assembly but if its behaving in the same way as your original, id say something is wrong

 

 

nacho

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 14 of 22

salariua
Mentor
Mentor

@NachoShaw wrote:

Hi

 

First, your ASM looks for the files

 

Box.ipt

FACE PLATE.ipt

GIB PLATE.ipt

 

so I can only assume it refers to 1, 2, 3 respectively.

 

Appologize for that..  thought i fixed the references, you are correct to use them in that order 1, 2, 3.

 

Second, there is something going on with your Assy. I cant even turn off the visibility of a part. If I create a new Assy and place the same parts, I don't get any CoG per part and visibility works fine.

 

I understand that there are issues with the assembly, big issues, I was hoping that forcing the COG via code would work.

 

In an assembly, the CoG should only show you the Assembly level CoG and not the parts. when you got to part level, you can show CoG for that part.

 

Don't know whats going on with your specific assembly but if its behaving in the same way as your original, id say something is wrong

 

these are completly different clients, differerent support tickets, scenarios really.

 

 

nacho

 


The reason I asked for your help guys is because I see in the properties of files, custom iprops some fields which seem o be done via 3rd party app and I was hoping that I can force it with code.

 

Take a look at file 2 or 3's iproperties custom tab. There are some custom props

 

CQTools_Weight

 

CQTools_X

 

CQTools_y

 

CQTools_z

 

That's why I thought it might be possible to do via vb.

 

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
0 Likes
Message 15 of 22

NachoShaw
Advisor
Advisor

Hi

 

I don't think the custom iProperties are related to the issue. By deleting the properties completely, there is zero affect to the part and the displaying of the CoG. The custom iProperties have nothing to do with any display of any indicator and are really nothing more than text holders.

 

Have you tried copying all of the parts as a mass selection and pasting them into a new assembly? works for me.

 

nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 16 of 22

salariua
Mentor
Mentor

HI Nacho,

 

I am not saying it's he iproperteis but rather that being a clue that a 3rd party app was used which corrupted the assembly.

 

I know copying the files fixes the issues, I recommended promote, demote because it keeps constraints between models but I was intrigued and wanted to see if we can fix this by other means.

 

Besides, on the first example there are too many planes, assembly features, design view reps, lods, etc... that will be lost by a simple copy paste.

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
0 Likes
Message 17 of 22

NachoShaw
Advisor
Advisor

ahh ok. Is there any way of finding out what 3rd party application was used? at least then, it can be downloaded and run locally to see if the same issues arise which would be the first step to finding the solution.

 

I couldn't find anything on the App store so it could very well be a custom tool that isn't completing correctly.

 

if this is the case, you should start a new thread regarding the corrupted assembly file as this thread is specifically for turning off the CoG which doesn't seem to be the issue now. The potential corruption of the assembly from a 3rd party app is more likely to be the issue

 

Nacho 🙂

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes
Message 18 of 22

Owner2229
Advisor
Advisor

Nacho's explanation sounds about right to me.

 

It might be possible to write a rule (or an addin) that will reassemble the assy with all parts and even workplanes and features, but it would be a bit of coding...

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 19 of 22

ekinsb
Alumni
Alumni

I looked at this for a while and couldn't figure anything out and don't know how the file gets into this state.  I did find this though, so the behavior is a bug that has been fixed in Update 1 of Inventor 2016. 

 

https://knowledge.autodesk.com/support/inventor-products/troubleshooting/caas/sfdcarticles/sfdcartic...

 

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 20 of 22

salariua
Mentor
Mentor

Hi Brian,

 

thanks for that link and for taking the time to investigate it.

 

I am aware of that link and that 2016 sp1 addresses this but 2017 still has this issue as you've found out; I am guessing you used 2017 as well, and that's why it was still visible on your test

 

https://knowledge.autodesk.com/support/inventor-products/troubleshooting/caas/sfdcarticles/sfdcartic...

 

 

https://knowledge.autodesk.com/support/inventor-products/troubleshooting/caas/sfdcarticles/sfdcartic...

 

Every 10 days or so I get this problem from someone else.

Adrian S.
blog.ads-sol.com 

AIP2012-2020 i7 6700k AMD R9 370
Did you find this reply helpful ?
If so please use the Accepted Solutions or Like button - Thank you!
0 Likes