Discussion:
EAGLE 7.7: ULP: How to access attributes of parts with multiple gates correctly?
(too old to reply)
Markus Rudolf
2019-05-06 15:02:00 UTC
Permalink
I wrote an ULP that "retrofits" user attributes for BOM management like
ORDERCODE, COMMENT, SUPPLIER etc.

It iterates through all schematic sheets, all instances on the sheet and
checks if the instance has a package (to exclude mainly power supply
symbols from getting attributes as well)

It tries to read the attribute (to check if the attribute is already
there, and to not overwrite it in case it's already defined and set to a
value).

If the attribute is not found, the ULP is adding a line to an output
script that can be run later to "retrofit" all the needed attributes.

In general it works quite well, the problem starts when there is any
part that consists of multiple gates, like TTL logic with seperate power
gates.

From the debug output in the generated script I see that attributes are
only found on the "first" gate of the multi gate part.

The second+ gate returns no valid attribute even though if i check
manually with a right click in the schematic all attributes are there,
even on all "sub-gates" of a part.

My script then assumes there must be the attribute missing and
overwrites the attribute with an empty one, which also deletes the
attributes' values of the first gate of a part.

As result I lose any attribute values that existed before running my
script in any multigate part.

There is no iterator for gates of an instance so i have no idea how to
memorize or recognize that I'm accessing not the first gate of a part
but the second one so i could skip those entirely (obviously the data is
attached internally to the the first gate of an instance, so i could
skip any other gates)

I'm kinda stuck here. Maybe someone from the good old eagle times or
former CadSoft employees can have a look at this and make suggestions?

I attach the script as reference (the V6 stems from it was written
originally for V6 but it has the same problem there)

Cheers,

Markus
Rob Pearce
2019-05-06 17:24:42 UTC
Permalink
Post by Markus Rudolf
In general it works quite well, the problem starts when there is any
part that consists of multiple gates, like TTL logic with seperate power
gates.
From the debug output in the generated script I see that attributes are
only found on the "first" gate of the multi gate part.
The second+ gate returns no valid attribute even though if i check
manually with a right click in the schematic all attributes are there,
even on all "sub-gates" of a part.
My script then assumes there must be the attribute missing and
overwrites the attribute with an empty one, which also deletes the
attributes' values of the first gate of a part.
I haven't tried this but...

I see you're checking the attributes() member of the instance. Have you
tried using the equivalent member of the part, instead? So instead of:


I.attributes(attr)
{

use:


I.part.attributes(attr)
{
Lorenz
2019-05-07 06:15:20 UTC
Permalink
Post by Rob Pearce
Post by Markus Rudolf
In general it works quite well, the problem starts when there is any
part that consists of multiple gates, like TTL logic with seperate power
gates.
From the debug output in the generated script I see that attributes are
only found on the "first" gate of the multi gate part.
that would be the gate used to asssign the attributes in the first
place.
Using the part name without gate index (IC1 vs. IC1A for instance)
with the attribute command defaults to the 'first' gate of a multi
gated part.
Post by Rob Pearce
Post by Markus Rudolf
The second+ gate returns no valid attribute even though if i check
manually with a right click in the schematic all attributes are there,
even on all "sub-gates" of a part.
the properties dialog shows all attributes of a part, regardless which
gate you used to invoke it.
Post by Rob Pearce
Post by Markus Rudolf
My script then assumes there must be the attribute missing and
overwrites the attribute with an empty one, which also deletes the
attributes' values of the first gate of a part.
I haven't tried this but...
I see you're checking the attributes() member of the instance. Have you
I.attributes(attr)
{
I.part.attributes(attr)
{
if you only need attributes on a part and not on a gate level

| schematic(SCH) SCH.parts(PAR) PAR.attributes(ATT) {...}

is the way to go. Using

| schematic(SCH) SCH.sheets(SHE) SHE.instances(INS) INS.attributes(ATT) {...}

is only required if you need to know which of the attributes of a part
are assigned to special gate(s).
This variant also lists attributes that are visible for the gate (an
attribute can be display at more then one gate).
--
Lorenz
Markus Rudolf
2019-05-07 09:05:49 UTC
Permalink
Post by Lorenz
if you only need attributes on a part and not on a gate level
| schematic(SCH) SCH.parts(PAR) PAR.attributes(ATT) {...}
is the way to go. Using
| schematic(SCH) SCH.sheets(SHE) SHE.instances(INS) INS.attributes(ATT) {...}
is only required if you need to know which of the attributes of a part
are assigned to special gate(s).
This variant also lists attributes that are visible for the gate (an
attribute can be display at more then one gate).
I think the problem was (the script I wrote some years ago, but still it
shot me in the foot yesterday again so I try to fix it once and for all)
that the generated script needs to know also the X and Y position of the
part to apply the attributes (it even checks which measurement system is
in use (mm/mil/inch) and adopts the commands accordingly.

Maybe this whole approach was stupid back then but I think it was the
only way getting it running at all.

I'll try your suggestion and see if it improves things or breaks it
completely :)

Markus
Lorenz
2019-05-07 09:29:47 UTC
Permalink
Post by Markus Rudolf
Post by Lorenz
if you only need attributes on a part and not on a gate level
| schematic(SCH) SCH.parts(PAR) PAR.attributes(ATT) {...}
is the way to go. Using
| schematic(SCH) SCH.sheets(SHE) SHE.instances(INS) INS.attributes(ATT) {...}
is only required if you need to know which of the attributes of a part
are assigned to special gate(s).
This variant also lists attributes that are visible for the gate (an
attribute can be display at more then one gate).
I think the problem was (the script I wrote some years ago, but still it
shot me in the foot yesterday again so I try to fix it once and for all)
that the generated script needs to know also the X and Y position of the
part to apply the attributes (it even checks which measurement system is
in use (mm/mil/inch) and adopts the commands accordingly.
Maybe this whole approach was stupid back then but I think it was the
only way getting it running at all.
I'll try your suggestion and see if it improves things or breaks it
completely :)
you don't need coordinates for the most task.

attribute PARTNAME ATTRIBUTENAME 'ATTRIBUTEVALUE';

does the trick nicely. If you don't want to display the attributes in
the schematic too, you need

change display off;

before adding new attributes. Otherwise the show up in the schematic.


You can even pick up visible attributes using

move PARTNAME>ATTRIBUTENAME (...);
--
Lorenz
Markus Rudolf
2019-05-07 09:53:33 UTC
Permalink
Post by Lorenz
you don't need coordinates for the most task.
attribute PARTNAME ATTRIBUTENAME 'ATTRIBUTEVALUE';
does the trick nicely. If you don't want to display the attributes in
the schematic too, you need
change display off;
Yeah there was some old dead code in that tricked me. My script actually
does that. Problem is accessing parts not on the current sheet. I just
did a quick test on an old project without attributes at all (from V5)
consisting of 4 sheets and C1-C18 on .S1 and C19++ on .S2

Now I get an error when trying to set attributes for C19 as it is not on
the sheet (somehow its stupid one cannot reference a part by its unique
name in a command by just calling it by its name...)

Markus
Markus Rudolf
2019-05-07 09:59:51 UTC
Permalink
The problem boils down to this, I guess thats why I ended up using the
instance loop in the first place:

https://www.element14.com/community/thread/32565/l/attribute-command-for-parts-in-another-sheet?displayFullThread=true
Markus Rudolf
2019-05-07 09:52:48 UTC
Permalink
Post by Lorenz
you don't need coordinates for the most task.
attribute PARTNAME ATTRIBUTENAME 'ATTRIBUTEVALUE';
does the trick nicely. If you don't want to display the attributes in
the schematic too, you need
change display off;
Yeah there was some old dead code in that tricked me. My script actually
does that. Problem is accessing parts not on the current sheet. I just
did a quick test on an old project without attributes at all (from V5)
consisting of 4 sheets and C1-C18 on .S1 and C19++ on .S2

Now I get an error when trying to set attributes for C19 as it is not on
the sheet (somehow its stupid one cannot reference a part by its unique
name in a command by just calling it by its name...)

Markus
Markus Rudolf
2019-05-07 09:47:15 UTC
Permalink
Post by Lorenz
if you only need attributes on a part and not on a gate level
| schematic(SCH) SCH.parts(PAR) PAR.attributes(ATT) {...}
is the way to go.
I tried that. It in principle works, the problem is, the generated
script fails on setting the attributes when the part is not on the
visible sheet.

Is there any way to address a part from a script by it's name when it's
on a different sheet?

I could in theory switch to the sheet for each part, but how do I find
out which sheet a part is on just in the SCH context?

Markus
Lorenz
2019-05-08 05:40:57 UTC
Permalink
Post by Markus Rudolf
Post by Lorenz
if you only need attributes on a part and not on a gate level
| schematic(SCH) SCH.parts(PAR) PAR.attributes(ATT) {...}
is the way to go.
I tried that. It in principle works, the problem is, the generated
script fails on setting the attributes when the part is not on the
visible sheet.
Is there any way to address a part from a script by it's name when it's
on a different sheet?
I could in theory switch to the sheet for each part, but how do I find
out which sheet a part is on just in the SCH context?
schematic(SCH) SCH.parts(PAR) PAR.instances(INS) INS.sheet
--
Lorenz
Markus Rudolf
2019-05-08 12:06:45 UTC
Permalink
Post by Lorenz
schematic(SCH) SCH.parts(PAR) PAR.instances(INS) INS.sheet
Yeah got it, it works now. Thx a lot!

Loading...