Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Knowledge Fusion question: obtain name of master part

Status
Not open for further replies.

potrero

Mechanical
Aug 30, 2007
516
0
0
US
In working with Drafting Templates (and using the master model method, where the master model is the only component of the drawing), it would be quite useful to programmatically access the name of the master part. This, for instance, could then be used to set the value of the "DB_PART_DESC" attribute in the drawing file.

For example, let's say the master part name is: "123456.prt", and let's say it has a description attribute, "DB_PART_DESC" set to "COVER PLATE".

If one could use Knowledge Fusion or some other programmatic means to obtain a string of the master part name, then you could very easily use Knowledge Fusion to then access the DB_PART_DESC parameter of the MASTER part as follows:

ug_askAttrValue_("123456.prt", "PART_ATTRIBUTE", "DB_PART_DESC")

If the programmatic means to access the master part name had allowed creation of a parameter, then this would be even nicer, and could be implemented in the Expression Editor as:

master_name = 123456.prt
DB_PART_DESC_Attribute = ug_setPartAttrValue ("DB_PART_DESC", ug_askAttrValue_(master_name, "PART_ATTRIBUTE", "DB_PART_DESC"))

where the variable, "master_name" is of String type, and "DB_PART_DESC_Attribute" is of Integer type.


Now, I've tried a number of ways to obtain the Master part name with KF; for example:

1. asm_struct = ug_askAssemblyStructure("");
this yields a list, which appears to have the master part name string as the second level. But, then, how do you access this string?? In looking through the available List KF functions, I can't find one that will spit out the master part name. For instance, first({asm_struct}) just returns "asm_struct"; and second({asm_struct}) returns NoValue. Argh.

2. It would seem that the Automatic Text functionality in drafting templates might be useful... the function, <W@$SH_MASTER_PART_NAME> seems to do exactly what I want, except that I can't figure out how to access this string for use in any other formulas, such as above. Also, I can't figure out how to access Automatic Text inside Knowledge Fusion.

So, if anyone has any ideas or can help, it'd be great! Thanks.
 
Replies continue below

Recommended for you

@scotty7,
Thanks for your response. You tipped me in the right direction - one of my problems was in syntax:
I had used
first({asm_struct})
instead of
first({asm_struct:})
(note the colon). However, even your syntax doesn't quite do the trick; what's needed is:
first(asm_struct:)
(drop the curly brackets, as asm_struct was already a list.) This returns a string which has the entire path + the filename of the top level part (the assembly part).

Now, getting back to my original desire, which is to programmatically determine an attribute in the Master for a drawing file...and to do this, we need to return the Master part name. A decent way to return the Master part name might be the following:
nth(2,flatten(asm_struct:));
or
second(flatten(asm_struct:));

But there's a catch.

Let's say you're making a multisheet, multiview detail assembly drawing, and you put Base Views of subcomponents or subassemblies into the drawing. Then, you're going to have "Components" in the Assembly structure in addition to the actual drawing Master part. Regardless of the fact that these parts are "Reference Only" in the Drafting application, they will still complicate our process of determining the Master part programmatically, because it (at least right now, to me) doesn't seem possible to predict the order of the assembly structure given by "flatten" or the ug_askAssemblyStructure("") command.

One possible way to handle this issue would be to run the KF program only upon drawing creation (ie: typical workflow is to open the assembly or part in Modeling, then click File>New, and select a drafting template...). This would guarantee that the only component of the Drawing file would be the master part, and then the "second(flatten(asm_struct:))" approach would correctly yield the Master part.

There's a further issue I still have to figure out, which is how to return only the part name, not the entire path (123456.prt instead of "C:\documents\123456.prt", or whatever).

This would all be so much easier if there was a straightforward way to just return the Master part; some function whose pseudocode would be:

mastermodel("")

and the output would be the string:

"123456.prt"

hmm...
 
A rapid response to your last question, quote:

"There's a further issue I still have to figure out, which is how to return only the part name, not the entire path (123456.prt instead of "C:\documents\123456.prt", or whatever)."

I belive there is a function, maybe it is called "split()" which lets you split strings into a list using a matching string. So if you use "\" as a matching string you'll get a list with the following content: {"C:", "documents", "123456.prt"}
so a call to last() will give you the name.

Regards,
Peter
 
Status
Not open for further replies.
Back
Top