1. Warum Java 1.4?
Ich würde die mind 1.5 besser 1.6 empfehlen (funktioniert einwandfrei mit Wildfire 2-4 und du kannst hashmaps verwenden)
2. Du kannst das über den ComponentPath oder über die BG-Struktur machen
Wenn dus über die BG Struktur machen willst hätte ich ein Bsp dazu (ComponentPath wäre besser da schneller; Waren meine ersten gehversuche in Java und JLINK also kann man durchaus besser lösen)
Übergeben werden muss eine assembly sowie eine Table (es werden zusätlich parameter ausgelesen)
public static Session session;
public static Map<String, Model> loaded_models = new HashMap<String, Model>();
public static Map<String, TreeItem> tree_items = new HashMap<String, TreeItem> ();
public static void addTreeItem(Tree tree, Assembly asm) {
int i;
Features features;
Features features_1;
ComponentFeat comp_feat;
ModelDescriptor dscr;
Assembly mod;
Parameter param;
ParamValue param_val;
String val;
tree_items.clear();
TreeItem parent_item = new TreeItem (tree,0);
try {
parent_item.setText(0, ((Solid)asm).GetDescr().GetFileName());
for (int f=1;f<BgBrowser.source.params.size();f++)
{
try{
val=(String)BgBrowser.source.params.get(f);
param = asm.GetParam(val.toUpperCase());
param_val = param.GetValue ();
parent_item.setText(f, param_val.GetStringValue());
}
catch (Exception e)
{
System.out.println("Fehler beim Parameter einlesen: "+e);
}
}
tree_items.put(parent_item.getText(0), parent_item);
find_item(asm, parent_item);
features = asm.ListFeaturesByType(Boolean.TRUE,FeatureType.FEATTYPE_COMPONENT);
for (int j=0;j<features.getarraysize();j++)
{
comp_feat = (ComponentFeat) features.get(j);
}
while (features.getarraysize()!=0) {
comp_feat = (ComponentFeat) features.get(0);
if (comp_feat.GetStatus().equals(FeatureStatus.FEAT_SUPPRESSED))
{
}
else
{
if (ModelType.getValue(comp_feat.GetModelDescr().GetType())==ModelType.getValue(ModelType.MDL_ASSEMBLY))
{
dscr = comp_feat.GetModelDescr();
System.out.println("Read: "+ dscr.GetFileName());
try{
mod = (Assembly)session.GetModelFromDescr(dscr);
features_1 = mod.ListFeaturesByType(Boolean.TRUE,FeatureType.FEATTYPE_COMPONENT);
if (features_1.getarraysize()>0){
for (i=0;i<features_1.getarraysize();i++)
{
features.insert(i+1, features_1.get(i));
}
find_item (comp_feat);
}
}
catch (Exception e){
System.out.println("Fehler beim lesen: " + e);
}
}
}
features.removerange(0, 1);
}
} catch (jxthrowable e) {
System.out.println ("Fehler beim erstellen: "+e);
}
}
public static void find_item(ComponentFeat cur_feat)
{
TreeItem child_item;
TreeItem item;
Features children;
ComponentFeat child;
ComponentFeat child_child;
ModelDescriptor dscr;
Assembly mod;
Parameter param;
ParamValue param_val;
Model child_model;
String val;
Parameter param_qty;
ParamValue param_qty_value;
Parameter param_pos;
ParamValue param_pos_value;
int sap_qty = source.getCol("Sap_Quantity");
int sap_pos = source.getCol("Sap_Position");
try
{
item = (TreeItem)tree_items.get(cur_feat.GetModelDescr().GetFileName());
dscr = cur_feat.GetModelDescr();
mod = (Assembly)session.GetModelFromDescr(dscr);
children = mod.ListFeaturesByType(Boolean.TRUE,FeatureType.FEATTYPE_COMPONENT);
for (int j=0; j<children.getarraysize();j++)
{
child_child = (ComponentFeat) children.get(j);
if (ModelType.getValue(child_child.GetModelDescr().GetType())==ModelType.getValue(ModelType.MDL_ASSEMBLY)| |
ModelType.getValue(child_child.GetModelDescr().GetType())==ModelType.getValue(ModelType.MDL_PART))
{
child = (ComponentFeat) children.get(j);
child_item = new TreeItem(item,0);
child_item.setText(0, child.GetModelDescr().GetFileName());
try{
param_qty = child.GetParam("SAP_QUANTITY");
param_qty_value = param_qty.GetValue();
child_item.setText(sap_qty,param_qty_value.GetDoubleValue()+"");
}
catch (Exception e)
{
}
try{
param_pos = child.GetParam("Sap_Position");
param_pos_value = param_pos.GetValue();
child_item.setText(sap_pos,param_pos_value.GetStringValue());
}
catch (Exception e)
{
}
child_model = session.GetModelFromDescr(child.GetModelDescr());
if (child_model!=null)
{
loaded_models.put(child_model.GetFileName(),
child_model);
}
for (int f=1;f<BgBrowser.source.params.size();f++)
{
try
{
val=(String)BgBrowser.source.params.get(f);
param = child_model.GetParam(val.toUpperCase());
param_val = param.GetValue ();
child_item.setText(f, param_val.GetStringValue());
}
catch (Exception e){
System.out.println("Fehler beim Parameter einlesen: "+e);
}
}
tree_items.put(child_item.getText(0),child_item);
}
}
}
catch (jxthrowable e)
{
System.out.println("Couldn´t find Item: "+e);
}
}
public static void find_item(Assembly asm, TreeItem item)
{
TreeItem child_item;
Features children;
ComponentFeat child;
ComponentFeat child_child;
Parameter param;
ParamValue param_val;
Model child_model;
String val;
Parameter param_qty;
ParamValue param_qty_value;
Parameter param_pos;
ParamValue param_pos_value;
int sap_qty = source.getCol("Sap_Quantity");
int sap_pos = source.getCol("Sap_Position");
try {
children = asm.ListFeaturesByType(Boolean.TRUE,FeatureType.FEATTYPE_COMPONENT);
for (int j=0; j<children.getarraysize();j++)
{
child_child = (ComponentFeat) children.get(j);
if (ModelType.getValue(child_child.GetModelDescr().GetType())==ModelType.getValue(ModelType.MDL_ASSEMBLY)| |
ModelType.getValue(child_child.GetModelDescr().GetType())==ModelType.getValue(ModelType.MDL_PART))
{
child_item = new TreeItem(item,0);
child = (ComponentFeat) children.get(j);
try{
param_qty = child.GetParam("SAP_QUANTITY");
param_qty_value = param_qty.GetValue();
child_item.setText(sap_qty,param_qty_value.GetDoubleValue()+"");
}
catch (Exception e)
{
}
try{
param_pos = child.GetParam("Sap_Position");
param_pos_value = param_pos.GetValue();
child_item.setText(sap_pos,param_pos_value.GetStringValue());
}
catch (Exception e)
{
}
child_item.setText(0, child.GetModelDescr().GetFileName());
tree_items.put(child_item.getText(0),child_item);
child_model = session.GetModelFromDescr(child.GetModelDescr());
if (child_model!=null)
{
loaded_models.put(child_model.GetFileName(),
child_model);
}
for (int f=1;f<BgBrowser.source.params.size();f++)
{
try
{
val=(String)BgBrowser.source.params.get(f);
param = child_model.GetParam(val.toUpperCase());
param_val = param.GetValue ();
child_item.setText(f, param_val.GetStringValue());
}
catch (Exception e)
{
}
}
}
}
}
catch (jxthrowable e) {
}
}
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP