CREO JLINK - List Sub Dependencies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
CREO JLINK - List Sub Dependencies
Hello,
Thanks for helping me out earlier, I was hoping if someone can help on this. What I need is to list down all dependencies of a Drawing, currently I am using model.ListDependencies(), but it only lists top-level.
For example,
Drawing
____Assembly
____________Model 1
____________Model 2
Currently I only get Assembly, not Model 1 and Model 2. I just need the filenames of sub-models.
Thanks
Solved! Go to Solution.
- Labels:
-
Jlink
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
you need to recursively list dependencies for every dependency get by listDependencies
this example is similar to what you need
it list all files in folders and subfolders (in your case it will be dependencies and subdependencies)
import java.io.File;
public class Filewalker {
public void walk( String path ) {
File root = new File( path );
File[] list = root.listFiles();
if (list == null) return;
for ( File f : list ) {
if ( f.isDirectory() ) {
walk( f.getAbsolutePath() );
System.out.println( "Dir:" + f.getAbsoluteFile() );
}
else {
System.out.println( "File:" + f.getAbsoluteFile() );
}
}
}
public static void main(String[] args) {
Filewalker fw = new Filewalker();
fw.walk("c:\\" );
}
}
- Tags:
- nee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
you need to recursively list dependencies for every dependency get by listDependencies
this example is similar to what you need
it list all files in folders and subfolders (in your case it will be dependencies and subdependencies)
import java.io.File;
public class Filewalker {
public void walk( String path ) {
File root = new File( path );
File[] list = root.listFiles();
if (list == null) return;
for ( File f : list ) {
if ( f.isDirectory() ) {
walk( f.getAbsolutePath() );
System.out.println( "Dir:" + f.getAbsoluteFile() );
}
else {
System.out.println( "File:" + f.getAbsoluteFile() );
}
}
}
public static void main(String[] args) {
Filewalker fw = new Filewalker();
fw.walk("c:\\" );
}
}
- Tags:
- nee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you, yes I found no method in API to do this, had to create own method which iterates over each dependency.
Here it is,
Models dependModels = drawingFile.ListModels();
String modelName = "";
for (int i = 0; i < dependModels.getarraysize(); i++) {
Model singleModel = dependModels.get(i);
if (singleModel.GetType() == ModelType.MDL_ASSEMBLY) {
Assembly as = (Assembly) singleModel;
Dependencies asDependencies = as.ListDependencies();
for (int j = 0; j < asDependencies.getarraysize(); j++) {
modelName = asDependencies.get(j).GetDepModel().GetFileName();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
There is no such method, you need to create your own recursive method. This will list first and sub level dependencies:
static void listAllDependencies(Assembly asm, Set<ModelDescriptor> deps) throws jxthrowable {
Dependencies dependencies = asm.ListDependencies();
for(int i = 0; i < dependencies.getarraysize(); i++) {
Dependency dependency = dependencies.get(i);
ModelDescriptor md = dependency.GetDepModel();
ModelType type = md.GetType();
deps.add(md);
if(type.getValue() == ModelType._MDL_ASSEMBLY) {
Assembly subAsm = (Assembly) session.RetrieveModel(md);
listAllDependencies(subAsm, deps);
}
}
}
To try it you can do
Assembly asm = (Assembly) session.GetCurrentModel();
Set<ModelDescriptor> deps = new HashSet<>();
listAllDependencies(asm, deps);
StringBuilder sb = new StringBuilder();
for(ModelDescriptor md : deps) {
sb.append(md.GetFileName()).append("\n");
}
session.UIShowMessageDialog(sb.toString(), null);