cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Jlink example

byork
17-Peridot

Jlink example

I was wondering if anyone has a jlink program dealing with layer manipulation they wouldn't mind sharing. (Like moving items from one layer to another).


Thanks in advance.

1 REPLY 1
byork
17-Peridot
(To:byork)

Thanks to Brian Krieger, Alfonso Medina & PTC Support for getting pointed int the correct location.

Here is a snippet of the code I can up with.
moveweldsquilts() remove the weld quilts from the quilts layer if they exist.
checklayer1() checks to see if the layer WELD_XXX exists and if not to creates it.


public void moveweldsquilts(){
try{
ModelItems feats2 = model.ListItems(ModelItemType.ITEM_FEATURE);
printLog("Number of feats found: " + feats2.getarraysize());
for(int w=0; w<feats2.getarraysize(); w++){<br="/> Feature feat2 = (Feature) feats2.get(w);
// only process fillet weld features
if(feat2.GetFeatType() == FeatureType.FEATTYPE_WELD_FILLET || feat2.GetFeatType() == FeatureType.FEATTYPE_WELD_GROOVE || feat2.GetFeatType() == FeatureType.FEATTYPE_WELD_PLUG_SLOT){
printLog("Found weld feature");
//Getting quilts for weld feature
ModelItems findquilts = feat2.ListSubItems(ModelItemType.ITEM_QUILT);
//Getting the array of quilts
for(int w2=0; w2<findquilts.getarraysize(); w2++){<br="/> //printLog("quilt. " + findquilts);
//Getting the feature
Quilt quilts = (Quilt) findquilts.get(w2);
printLog("Weld quilt ID = " + quilts.GetId() );
//Looping the quilts layer to get ids to match
Layer myCurLayer3 = (Layer)model.GetItemByName(ModelItemType.ITEM_LAYER, "Quilts");
ModelItems itemlist1 = myCurLayer3.ListItems();
printLog("Objects on Quilts Layer = " + itemlist1.getarraysize());
for(int l=0; l<itemlist1.getarraysize(); l++){<br="/> Quilt quilts2 = (Quilt) itemlist1.get(l);
printLog("Quilts Layer Item Id = "+ quilts2.GetId());
//Check to see if I should remove the weld quilt from the quilt layer
if(quilts.GetId() == quilts2.GetId()){
printLog(quilts.GetId() + " == " + quilts2.GetId() + " Quilt #: " + l);
myCurLayer3.RemoveItem(quilts);
}else{
//printLog("No match");
}

}
}

}
}


}catch(Exception e){
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
printLog("moveweldsquilts: " + sw.toString());
}

}

public void checklayer1(){
try{
//going to make sure the weld_xxx layer exists
ModelItems layers = model.ListItems(ModelItemType.ITEM_LAYER);
printLog("number of layers = " + layers.getarraysize());
String weldXXXfound = "No";
for(int i=0; i<layers.getarraysize(); i++){<br="/> Layer layer = (Layer) layers.get(i);
printLog(layer.GetName());
if (layer.GetName().equals("WELD_XXX")){
printLog("found WELD_XXX");
weldXXXfound = "yes";
}
}
if(weldXXXfound.equals("yes")){
printLog("found WELD_XXX");
}else{
printLog("Did not find WELD_XXX layer going to create it.");
model.CreateLayer("Weld_XXX");
}
printLog("Done");
}catch(Exception e){
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
printLog("checklayer1: " + sw.toString());
}
}


Announcements


Top Tags