Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
I am using creo object toolkit java to make some secondary developing.
Suppose I have get the ComponentPath of a part or component in an assembly model. Which function can I use to hide and unhide the part or check its hidden status. I read the usergudie a thousand times and could not find one. Belows are functions I have tested.
com.ptc.pfc.pfcModel.Model.Display
com.ptc.pfc.pfcSelect.Selection.Display
com.ptc.wfc.wfcSolid.WSolid.DisplaySolid
Sadly, none of them help.
Does the toolkit provide the function to programmatically hide and unhide part, just like hit the button in this picture?
Solved! Go to Solution.
Thank you very much for your timely reply.
Although the code is not written in Java, it still inspired me a lot.
In summary, the program goes like this:
In this way, you can switch the hidden status programmtically.
Here I paste the Java Code.
public void OnCommand() throws jxthrowable {
// STEP 1 Get the Model of [40], the part's parent.
Model model = session.GetCurrentModel();
Assembly assembly = (Assembly) model;
intseq path = intseq.create();
path.append(40);
ComponentPath componentPath = pfcAssembly.CreateComponentPath(assembly, path);
WSolid solid = (WSolid) componentPath.GetLeaf();
// STEP 2 Get the ModelItem [43] of Model [40].
WModelItem modelItem = (WModelItem) solid.GetItemById(ModelItemType.ITEM_FEATURE, 43);
//STEP 3 Check if the ModelItem [43] ishidden.
//STEP 4 If true, unhide it; if false, hide it.
if(modelItem.IsHidden()){
modelItem.Unhide();
}else {
modelItem.Hide();
}
}
Thanks again, VladimirN.
Have a good day!😀
Take a look - "How to hide and unhide with toolkit, check out my code!": https://community.ptc.com/t5/Customization/How-to-hide-and-unhide-with-toolkit-check-out-my-code/td-p/910320
Thank you very much for your timely reply.
Although the code is not written in Java, it still inspired me a lot.
In summary, the program goes like this:
In this way, you can switch the hidden status programmtically.
Here I paste the Java Code.
public void OnCommand() throws jxthrowable {
// STEP 1 Get the Model of [40], the part's parent.
Model model = session.GetCurrentModel();
Assembly assembly = (Assembly) model;
intseq path = intseq.create();
path.append(40);
ComponentPath componentPath = pfcAssembly.CreateComponentPath(assembly, path);
WSolid solid = (WSolid) componentPath.GetLeaf();
// STEP 2 Get the ModelItem [43] of Model [40].
WModelItem modelItem = (WModelItem) solid.GetItemById(ModelItemType.ITEM_FEATURE, 43);
//STEP 3 Check if the ModelItem [43] ishidden.
//STEP 4 If true, unhide it; if false, hide it.
if(modelItem.IsHidden()){
modelItem.Unhide();
}else {
modelItem.Hide();
}
}
Thanks again, VladimirN.
Have a good day!😀
You're welcome.
