Ilogic Parameter Passing

Ilogic Parameter Passing

Anonymous
Not applicable
1,035 Views
9 Replies
Message 1 of 10

Ilogic Parameter Passing

Anonymous
Not applicable

Hi,

 

I am trying to get a code that will allow the user to pass through variables from an assembly into all the referenced parts. I seem to have this mostly working but i'm running into a weird error that i can't figure out what the cause would be. 

 

A little information on the code itself, the code first loops through all parameters in the assembly finding unique names, i.e. not d#, then using whether the parameter is key to decide if it should be passed or not. code includes methods to add or remove variables. the code then loops through all referenced documents, make a few checks, such as is modifiable or has a skip requirement. I then loop through all parameters in the referenced document and change its value if it is the correct name.

 

The code runs perfectly when i first open a document, but as soon as i hit save i start getting errors. i know for a fact that the error is occurring when doing the following, oDoc.ComponentDefinition.Parameters.Count. I have attached the code if you would like to take a look.

 

I'm mostly wondering is there a better way to get the number of parameters or a better way to loop through them. i know i could just use Parameter(oDoc, "Variable Name") = vVal, and either contain this in a try catch block or turn errors to quiet, but i would like to know if there is an error passing a variable so that i can inform the user, so i at least need to differentiate parameter doesn't exist, from other errors, as i know there will be a lot of doesn't exist errors.

 

Thanks in advance,

Logan

0 Likes
1,036 Views
9 Replies
Replies (9)
Message 2 of 10

philip1009
Advisor
Advisor

What does the error window tell you when it fails to save, is it just saving that makes the issue, or is it changing or possibly adding the parameter?  Under the Parameters property are properties for ModelParameters, ReferenceParameters, and UserParameters that then allow methods to add a Parameter and counting.  I'm guessing you only need to go under UserParameters since that's the recommended place to put your important parameters.

0 Likes
Message 3 of 10

Anonymous
Not applicable

There is no error in saving, the error is in running the code. I want to be able to pass model, reference, and user parameters. I don't have a problem in the assembly, its in the counting of parameters in the sub assemblies. the code is meant to be manually ran when the user want to pass variables. right now the error causing line is contained in a try catch block. but i believe when its not it will throw a member not found error. 

0 Likes
Message 4 of 10

Anonymous
Not applicable

I just tried running the rule where i'd try counting just the user parameters, reference parameters, and model parameters individually or just 1 set and i got a similar result. 

 

Just to clarify the problem:

 

First Open -                                       Code Works

Make Model Changes -                    Code Works

Save Assembly -                               Code Works

Trigger Save on Dependent Part - Errors start

Close/Open Assembly -                    Code Works

 

The part that i'm having the most part diagnosing is that the code works perfectly until you go to save and save the dependant part that you just changed through the code. it will then sometimes throw an error, sometimes it will take 2/3 saves before it throws the error. i have not had the code error before saving a dependent, at least not for the same reason. The fact that closing and opening the assembly allows it to work again is what i'm having trouble understanding, if it just had an error all the time it would make more sense to me.

0 Likes
Message 5 of 10

philip1009
Advisor
Advisor

Before causing the save trigger, go through a test document to see if the parameters pass through the way you want them to.

 

One thing I can think of to make looping through the parameters easier is to loop each parameter in the collection:

"For Each oUserParam In ThisDoc.Document.ComponentDefinition.Parameters.UserParameters"

That way you don't have to waste a line of code to get each parameter through its index number.  I also definitely recommend that any and all important parameters be put in User Parameters, this will also save the time of checking against all d## parameters and only having to check if it's keyed or not.  Checking and editing Modeling Parameters can have issues, and Reference Parameters can't be edited in the table.  Therefore only checking and passing User Parameters can eliminate a lot of error possibilities.

 

As for the random errors on save, I'm not sure about the cause yet, if it was caused by the code, then it would happen every time.  I'll keep looking through the code to see if there's other possibilities.

 

Is the error only happening on Sheet Metal Parts or other specialty parts like those made in the Cable & Harness or Tube & Pipe environments?

0 Likes
Message 6 of 10

Anonymous
Not applicable

Thanks Philip for taking the time to look. I understand where your coming from with regards to the user parameters, and maybe i'll consider making the change, and also check with coworkers on this practice. personally i prefer to be able to change the variable from inside the sketches/features directly, which means i like working with the model parameters. this code is also not meant to be ran constantly, so a little extra time isn't a deal breaker in my opinion, but again i'll check with coworkers.

 

the problem specifically i'm seeing in the code was on line 152 of what i posted. I tried to run the code in the past using for each oparam in oDoc.ComponentDefinition.Parameters, but i believe this was generating a similar error, its harder to confirm, due to containing the entire loop in a try/catch, but i know it gave a similar response of working when first open and then not working after a save. and it would also mean i can't check if a specific variable had a failure in a part. the current method lets me check if a part is failing as well as checking if a parameter is failing, but of course if i figure out how to not have a part failure, i can go back to that method.

 

i only run the code in assemblies, but the problem line doesn't seem to be to a specific type of part, it pulls out library and standard content center parts as those are not modifiable to begin with, but it looks like the problem will be sheet metal, regular, custom content center, derived, the only two things i don't see errors on are imported parts, and bases components that aren't in the assembly, but a part is derived from.

0 Likes
Message 7 of 10

Anonymous
Not applicable

@philip1009 Have you tried to replicate the error, and if so were you able to do so?

0 Likes
Message 8 of 10

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous ,

 

After reading discussion in this post, I feel that a sample assembly file with related document would be helpful to reproduce the error. Is it possible to provide files? 

 

Please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 9 of 10

philip1009
Advisor
Advisor

I've tried replicating and can't get any errors so far.  I don't think it's something inherent in the code causing errors, otherwise it would happen more consistently, I think there's something specific to a part or assembly file that I haven't thought of yet.

0 Likes
Message 10 of 10

Anonymous
Not applicable

So i went to do a pack and go of the assembly i'm working on to upload to show you what was wrong, but i came across something interesting.

 

So in the past to try and figure out what was wrong, i've done the following:

  • Run it on different assemblies on my computer
  • had a coworker run it in one of the assemblies they were working on

After making the Pack and Go i opened it to make sure there was no problem with the files, and tried to run the code, could get the error to trigger. So i had a coworker download original files from vault, but couldn't get the error. i moved the files on my computer and got from vault, no error, and now it's not throwing the error every time after save, even on older assemblies that it was doing it on.

 

I can upload the pack and go if you would like to look at, but from what i can tell, you may not be able replicate the error. 

 

Next time i get the error, i'll remove the try block and get a screenshot of the error itself, but i believe it is a late get statement.

 

0 Likes