How to access parameters in a copied sketch

How to access parameters in a copied sketch

RanOutOfIdeasAgain
Observer Observer
254 Views
2 Replies
Message 1 of 3

How to access parameters in a copied sketch

RanOutOfIdeasAgain
Observer
Observer

Hey ilogic-community,

 

my aim is to copy a reference sketch multiple times and then change one specific parameter for each sketch. Copying works well, though the problem is that everytime I run my code, Inventor assigns new parameter names for the copied sketches, so I cannot predict how the parameter I need to change will be named.

 

My idea was to somehow use the current status option from ilogic that lists all parameters within the selected sketch. But I haven't found out how to access this list without gui. Maybe it is possible to access the ninth parameter in this list and change it instead of taking the parameter name (see marking in the picture)?

 

Or can you think of any other possibility? Is there maybe a way to assign parameter names while copying the sketch?

 

Thank you very much!

0 Likes
255 Views
2 Replies
Replies (2)
Message 2 of 3

J_Pfeifer_
Advocate
Advocate

Is there any other way you can target the copied sketch and find those sketch entities by using the evaluator? Length, area, and so on. I normally create a loop looking through all the parameters searching for one that matches something like: 

 

Dim LongerLine as sketchline = nothing

For each oLine as Line in osketch1.sketchlines 
   if oline.Evaluator.length = 10 then 
     LongerLine = oLine
   end if 
next

 

The above allows you to grab the dimension you may need. You can specify more than just one option. Note, that taking into consideration your needs and objects may change how you target or access these things. For example, the above will not work due to oLine not exposing the length. I have to get that value with another step. 

 

Another option you have, is if all parameters and inputs are identical other than their values. That is, if the number of lines and objects within the sketches are identical. You could work out indexing each line within the original sketch. Then using those index numbers to apply changes to those same entities or dimensions within the copied sketch. 

In this case it would look something like:

 

Dim oLineCount as integer = 1

For each oLine as Line in osketch1.sketchlines 
   if oline isnot nothing then 
      oLineCount = oLineCount + 1
      logger.info("oLine name: " & oLine.name & " Line number: " & oLineCount)
   end if 
next
'Then you set them later like this 
Dim oNewLine as line = osketch1.sketchlines.item(1) 'Where the 1 in this is any value you've found to hold the proper line object. 

 

The above is great for situations where the number of items or things you're searching for do not change in their searched order. That is, if you ran a check on one sketch vs another. Everything could be directly transferred to that sketch without adding or removing anything that messes with this index. 

 

Edited to add: Instead of targeting the sketch objects you could make a list of the parameters or dimensional constraints within the sketch object. The idea is getting to anything that holds a pattern you can then transfer to the copied sketches with new values. 

 

Message 3 of 3

WCrihfield
Mentor
Mentor

I am not sure if collection 'index' numbers will be maintained when using the PlanarSketch.CopyContentsTo method.  If so, then recording the index of an object in the original collection, to use in the new one would certainly be an option, but if you are going to iterate through a collection in its proper order, you would have to use a [For iStartIndex to iEndIndex...Next] type of loop, instead of the simpler [For Each oObj In oCollection...Next] type loop.

 

Another thought would be to use Attributes.  We can only access Attributes by code, not through the user interface, so it is not always the simplest option.  Nearly every type of 'real' object in Inventor has the AttributeSets property (for example:  DimensionConstraint.AttributeSets).  That is the entry way for creating a new AttributeSet within it, then a new Attribute within that new set.  The attribute is a very simple object, with a name, value type, and value.  The AttributeSet object that you create has a property (AttributeSet.CopyWithOwner) that you can set to True, and a property (AttributeSet.Copy) which indicates if this AttributeSet was created due to its owner object being copied.  On the back end, when you want to 'find' something in a document with an attribute, you can use the Document.AttributeManager and its powerfull methods.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes