Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Link Resolve Brainstorming / Efficiency

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
alyssaweaver
389 Views, 2 Replies

Link Resolve Brainstorming / Efficiency

I'm doing an open brainstorm right now of how to do this and am simply looking for a more efficient way (if there is one) to find a common suffix of a file. What I'm doing is renaming a set of files (parent project, children files, and chilren's children files), opening the new file, and resolving the links between the parts. Well, that's the basic way to explain it anyways. I'm very excited that I started learning VBA two weeks ago and am already almost done!

 

What I need to do to resolve the links is use the following:

 

Component.Replace("Old Part","New Part",False)


However, the way my files are set up are as follows:

 

Parent:

MyCodeWorks1.ipj

 

Children:

MyCodeWorks1-001.iam

MyCodeWorks1-002.iam

 

Children of Children:

MyCodeWorks1-003.ipt

MyCodeWorks1-004.ipt

MyCodeWorks1-005.ipt

MyCodeWorks1-006.ipt

etc.


I then rename my parent file to, say, "Yay32.ipj". All prefixes "MyCodeWorks" then change to prefix "Yay32". To fit the format for the replace component procedure, I need to grab the suffixes "001","002","003",etc.

 

I have two ideas so far and would love more input. I'm new to VBA and really don't know the most efficient way to do things yet. I'm posting my ideas below! Does anyone have a better or more efficient idea? This is more theoretical; I wouldn't need the actual code, just an idea!

 

1) When the user inputs "Old Name" and "New Name" into the initial renaming process, I could have it calculate the number of characters in each string and then skip that many characters in each to find the common suffix.

2) Search for the full prefix ("001")...this could cause problems because sometimes a file might read, say, SD5 001 - 001 . But maybe there's a way to search for that prefix after the hyphen, adding i=1 each time in a loop?

 

Thanks for any ideas ahead of time!!!

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
2 REPLIES 2
Message 2 of 3
alyssaweaver
in reply to: alyssaweaver

EDIT 1: I've been looking in to the idea of suffix trees. Maybe this could be a better way to go about solving this problem?

EDIT 2: I've looked in to applications of suffix trees, and that seems to be a plausible, if not complicated, solution. There's a similar application starting on slide 14, here:


http://www.cs.uku.fi/~kilpelai/BSA05/lectures/slides08.pdf


The difference would be instead of finding the LONGEST common string, I'd be looking for the LAST common string. Does anyone know of an easier way to do this before I start working on it?

 

 

Additional relevant links. I've also started a discussion on this on StackOverflow. Links HERE and HERE.

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
Message 3 of 3
alyssaweaver
in reply to: alyssaweaver

Possible solution, from StackOverflow:

 

"I am not sure a suffix trie would be much more efficient in your case.. You would need to build a map to store all the prefixes etc which depending on the amount of prefixes possible could take longer than just getting on and renaming it one by one. It seems that you are actually complicating and overkilling such a simple procedure. Why don't you use InStr(1, oldName, newName, vbTextCompare)? – mehow"

Link Here

 

 

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums