Rebuild function do not working with Inventor api.

Rebuild function do not working with Inventor api.

hayattangercekler2
Advocate Advocate
1,236 Views
9 Replies
Message 1 of 10

Rebuild function do not working with Inventor api.

hayattangercekler2
Advocate
Advocate
 
Although I change the length parameter of the frame part, whose length I want to change in Incentor, it does not change its length. Rebuild function with Inventor api "document.Rebuil(); , activeDocument.Rebuild();" I'm trying with. The function doesn't give an error but neither works. How can I fix this situation?
0 Likes
Accepted solutions (1)
1,237 Views
9 Replies
Replies (9)
Message 2 of 10

A.Acheson
Mentor
Mentor

Can you post the code your using and  a screenshot of the change? Have you tried to go into the sketch? This might cause it to refresh. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 10

hayattangercekler2
Advocate
Advocate

I am trying to implement this code. The reason I want to implement this is that although I changed the length parameter of the frame files, the change did not occur on the frame.

hayattangercekler2_2-1669611387587.png

 

hayattangercekler2_1-1669611227501.png

I get this error "The RPC server is unavailable."

hayattangercekler2_0-1669611098967.png

 

 

0 Likes
Message 4 of 10

A.Acheson
Mentor
Mentor

Are you changing the sketch parameter by code or manually? If by code can you provide the code and not just an image. It is hard for users to see issues when there is no way to reproduce the errors. Can you get the frame to update manually but not by code? 

I have had situations in another addin tube and pipe whereby updating a sketch route resulted in no change in the adaptive geometry. In that case editing the sketch by code and rebuilding/updating was all that was needed. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 10

hayattangercekler2
Advocate
Advocate

I am replacing the parameter with code. This is the code I'm using. Although the parameter has changed and the line is relative to it, the profile does not extend relative to the line. I need to do the update process with code. If I do it manually, I can't achieve my goal.

 

My parameter change code.

 

   public void ChangeParam(Document doc, string paramName, string paramValue)
        {

           

            UserParameters userParams;

            if (doc.DocumentType == DocumentTypeEnum.kPartDocumentObject)
            {
                Console.WriteLine("Part Document");
                PartComponentDefinition partComponentDef = ((PartDocument)doc).ComponentDefinition;
                Parameters docParams = partComponentDef.Parameters;
                userParams = docParams.UserParameters;


            }
            else if (doc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject)
            {
                Console.WriteLine("Assembly Document");
                AssemblyComponentDefinition assemblyComponentDef = ((AssemblyDocument)doc).ComponentDefinition;
                Parameters docParams = assemblyComponentDef.Parameters;
                userParams = docParams.UserParameters;
            }
            else
            {
                Console.WriteLine("Unknown Document");
                // unsupported doc type, throw excepstion
                throw new Exception("Unsupported document type: " + doc.DocumentType.ToString());
            }
            try
            {

                Console.WriteLine($"Setting {paramName} to {paramValue}");
                UserParameter modelParam = userParams[paramName];
                modelParam.Expression = paramValue;
                doc.Update();

            }
            catch (Exception e)
            {
                Console.WriteLine("Cannot update '{0}' parameter. ({1})", paramName, e.Message);
            }

        }

 

 

0 Likes
Message 6 of 10

JelteDeJong
Mentor
Mentor

Have you tried the update method instead of rebuild?

' Summary:
'     Performs compute operations on all of the entities within this Document's scope
'     that may be out of date with respect to their driving entities.
ThisDoc.Document.Update()

' Summary:
'     Method that performs compute operations on all of the entities within this Document's
'     scope that may be out of date with respect to their driving entities.
' Parameters:
'   AcceptErrorsAndContinue:
'     Optional argument that specifies if errors should be ignored and the update completed
'     or if the update should be aborted if an error occurs. If the IgnoreErrors argument
'     is set to True, errors are skipped and the update process continues. If IgnoreErrors
'     is set to False, the method returns as soon as the first error is encountered.
ThisDoc.Document.Update2()

 

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

0 Likes
Message 7 of 10

hayattangercekler2
Advocate
Advocate
Although the parameter of my profile, which I created with the frame with the inventor api, has changed, there is no change in the profile. I also tried the true versions of the update and rebuild commands, but it didn't work.
0 Likes
Message 8 of 10

CattabianiI
Collaborator
Collaborator

>> Are you changing the sketch parameter by code or manually?

> I am replacing the parameter with code.
I suppose you're changing the frame member parameter, what @A.Acheson was assuming is that you're changing the sketch parameter; that's how the frame generator works.

Let me add a thing.
Looking at your posts in the past few weeks what you're trying to achieve is very tricky and diffucult to maintain at least! 
What you're trying to do is to edit a frame generator without proper API, because frame generator API does not exist (vote this Idea.)
I suggest you - again - to deeply understand how frame generator works, if it's possible find a solution to your problem doable via UI, then try to implement the same workflow via API. Very few things can be done via API and not via UI. (EDIT: via API you can leverage the events triggering for example)
And if you find a possible solution try to post it in the Inventor Forum to know if it's the right approach to your frame generator problem. 
And maybe using the frame generator there's no solution at all and you have to change completely the approach to your problem.


0 Likes
Message 9 of 10

hayattangercekler2
Advocate
Advocate
Yes you are right, thank you for your suggestion. I'm not normally a cad programmer, but I'm trying to solve problems somehow.

In my problem on this issue, the "rebuild" function does not work both manually and with code. I tried to run it with a trigger in a rule, but the function is completely ineffective during my operations. When I turn it back on afterward, it becomes operational when the inventor is open with all its features. I can't figure out why this function doesn't work with both c# and vb ilogic. What is the reason of this ?
0 Likes
Message 10 of 10

hayattangercekler2
Advocate
Advocate
Accepted solution

In fact, my problem here was that the object created with the frame did not take shape in the desired size, although the parameter was changed. As a result of using an "application.Ready" feature, which I skipped using for this, by controlling it with a while loop, the frame size is shaped according to the desired parameter, even without the need for the "rebuild all" feature. This is my sample code block.


while (!_application.Ready)
{
Console.WriteLine(_application.Ready);
Thread.Sleep(200);
}

0 Likes