Copy Family

Copy Family

Anonymous
Not applicable
1,080 Views
11 Replies
Message 1 of 12

Copy Family

Anonymous
Not applicable

Continuing on this post : http://forums.autodesk.com/t5/inventor-customization/content-center-only-view-one-library/m-p/231783...

 

I want to use "Save Copy As" to copy an content center Family from a DIN library to my own custom library.

 

The content center has a function : FamilyManager.CopyFamily(familyID, FromLibraryID, ToLibraryId);

The FamilyID I can get, but I need to obtain the ID's of the source and target Library. How can I optain these ??

 

 

0 Likes
1,081 Views
11 Replies
Replies (11)
Message 2 of 12

adam.nagy
Autodesk Support
Autodesk Support

Hi Remy,

 

The FamilyId is the InternalName of the family.

So it would be something like this:

 

Unfortunately, this only seems to work well if in the same Inventor session you copied a family into your library through the UI - i.e. it's not very useful. I logged it in our system #142236

Don't forget that this is not a public API - that's why it's hidden.

Sub CCtest()
  Dim cc As ContentCenter
  Set cc = ThisApplication.ContentCenter
  
  Dim ctvn As ContentTreeViewNode
  Set ctvn = cc.TreeViewTopNode. _
    ChildNodes("Cable & Harness"). _
    ChildNodes("Connectors"). _
    ChildNodes("Discrete Wire")
    
  Dim cf As ContentFamily
  Set cf = ctvn.Families(1)
  
  Dim fm As FamilyManager
  Set fm = cc.FamilyManager

  Dim lm As LibraryManager
  Set lm = cc.LibraryManager
    
  ' With this I can check all the library names, internal names etc
  ' and use it in the next call of CopyFamily
  Dim str As String
  str = lm.GetServerLibraries()
  
  Debug.Print str
  
  str = fm.CopyFamily(cf.InternalName, cf.LibraryInternalName, "<your library's internal name>")
End Sub

The best would be if this was exposed in a public API. Maybe you could log it as a wish on the IdeaStation?

http://modthemachine.typepad.com/my_weblog/2015/07/tracking-api-wishes.html

 

Sorry for the bad news 😞

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 12

Anonymous
Not applicable

I tried this in the C# API and it crashed.

Instead of using cf.InternalName I had to do this :

 

string cfInternalname = "v3#" + cf.InternalName + "#";

 

In the UI I used "Copy to" and "Save Copy As", then run my code in the same session, but after the FamilyManager.CopyFamily() command, it returns a string (the same as I put in the function), but the amount of content center families isn't raised by one, so apperently the copy didn't work.

 

I thought there had to be another function to actually save this new family to the library or something like that.

 

Can you confirm that after the FamilyManager.CopyFamily function, your content library holds this new created family ?

 

 

 

0 Likes
Message 4 of 12

adam.nagy
Autodesk Support
Autodesk Support

"string cfInternalname = "v3#" + cf.InternalName + "#";"

I did not have to do that. Did the family get copied when you did that?

 

Once I copied a family into my library through the UI before running the code, then it succeeded without crashing Inventor. The family got copied into my library every time - even if Inventor crashed. However, that is not a really good workaround. 😕

 

So unfortunately, it looks like there is no safe way to do what you want programmatically. That's why I think the best would be if a wish for a public API was logged on IdeaStation.



Adam Nagy
Autodesk Platform Services
0 Likes
Message 5 of 12

Anonymous
Not applicable

Hi Adam,

 

Maybe the differences lies in the fact that you are programming in VB and I in C# ?

 

When I try the CopyFamily without the "v#3" in the stringname, inventor crashes. But when I do add them, Inventor doesn't crash but doesn't copy the family either 😞

 

For the time being, I could live with the fact to firstly do one family manually, but I just can't get the CopyFamily function to work 😞

 

I just added this question to the API IDEA forum. 

 

0 Likes
Message 6 of 12

adam.nagy
Autodesk Support
Autodesk Support

"v#3"

But where is that even coming from? Why adding that specific string?

 

I think it does not crash like that because you provide the wrong string and so it does not actually have to do the copying.

Inventor crashes as a result of the copying IF you did not copy another family into your library within the same Inventor session.

Also, it seemed to me that the family you copy through the UI should be from another branch of the CC tree than the one your code is trying to copy. Give that a try.



Adam Nagy
Autodesk Platform Services
0 Likes
Message 7 of 12

Anonymous
Not applicable

Okay, so I did a Copy to and a Save Copy As from a bolt in the Inventor ISO library to my own library with the UI.

 

Then I run my code:

 

_contentFamiliesList is a list of all the ContentFamilies.

targetLibrary is the internalname of my library

 

foreach (ContentFamily contentFamily in _contentFamiliesList)
{
// string famid = "v3#" + contentFamily.InternalName + "#";
string famid = contentFamily.InternalName;  // this first fam is a family from the Inventor DIN library
string libid = contentFamily.LibraryInternalName;
string newfam = _contcent.FamilyManager.CopyFamily(famid, libid, targetLibrary);

}

 

Now Inventor crashes and closes.

 

 

In this example I saw they used the "v3#" for the family id, so that's why I tried it.

http://modthemachine.typepad.com/my_weblog/2012/02/getting-data-from-content-center.html

 

 

0 Likes
Message 8 of 12

Anonymous
Not applicable
Strange, I did exactly the same without the "v3#" and all of the sudden it worked ?? Let's just say it isn't a stable way of working 🙂
0 Likes
Message 9 of 12

adam.nagy
Autodesk Support
Autodesk Support

I think this is a specialty of the GetContentObject function.

In the sample you could see that using '#' you can string values together: CC version + FamilyId + MemberId:

GetContentObject("v3#" & familyId.Value & "#" & strMemberId)

"Let's just say it isn't a stable way of working :)"

Yes, I agree. 😕



Adam Nagy
Autodesk Platform Services
0 Likes
Message 10 of 12

wolfgang_nickl
Advocate
Advocate

Hello together,
you use the FamilyManager with CopyFamily.

Is there a documentation for the FamilyManager, i can't find one.

Are there other functions, especially for replacing the family template?

 

Best Regards
Wolfgang

0 Likes
Message 11 of 12

Anonymous
Not applicable

Those objects (like FamilyManager) are hidden - i.e. not for public use - and so not documented either. But if you have questions about a specific function it has I can try to get some info about it.

As I mentioned in a previous reply the best would be to log this as a request on the Inventor IdeaStation to see how much interest there is in such API's:

http://modthemachine.typepad.com/my_weblog/2015/07/tracking-api-wishes.html

 

0 Likes
Message 12 of 12

or.mokhtar
Contributor
Contributor
Hello there,

Adam wonderful work you have achieved here. Have you ever found the chance to look for a way to can mimic the save copy as functionality for families.
Are there any intersting solutions you have found to be time reducing in the Content center libraries and families modifications area you can enlight me with?

Thanks & Regards
Omar Moktar
Automation Engineer
0 Likes