Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

"Member Not Found" Error when using iLogic to change the Material of Content Center parts

tbishop00
Contributor
Contributor

"Member Not Found" Error when using iLogic to change the Material of Content Center parts

tbishop00
Contributor
Contributor
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oFolderPath = ThisDoc.Path
Dim AssyName As String = "1001-"
Dim ShopField As String = "SB"

Dim oFSO As Object = CreateObject("Scripting.FileSystemObject")
Dim oFolder As Object = oFSO.GetFolder(oFolderPath)
Dim oFiles As Object = oFolder.Files
Dim BuyBiggest As Integer = 1

Dim AssetLib As AssetLibrary

Try
	AssetLib = ThisApplication.AssetLibraries.Item("MyCustom Material Library")
Catch
	MessageBox.Show("The MyCustom Material Library is not installed. Please install before continuing.", "Missing Material Library")
	Return
End Try

For Each oRefDoc As Document In oAsm.AllReferencedDocuments
	Dim oRefDocs = oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc)
	Dim NeedZero As String = ""
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
		Dim oRefDocPath As String = oRefDoc.FullFileName
		If oRefDoc.ComponentDefinition.IsContentMember() = True Then
			If BuyBiggest < 10 Then NeedZero = "0"
			Dim SavePartName As String = AssyName & ShopField & NeedZero & CStr(BuyBiggest)
			
			oRefDoc.SaveAs(oFolderPath & "\" & SavePartName & ".ipt", 0)

			Dim oRefDocMat As Asset = Nothing

			oRefDocMat = AssetLib.MaterialAssets.Item("STEEL")
			
			oRefDocMat.CopyTo(oRefDoc)
			oRefDoc.ActiveMaterial = oRefDoc.MaterialAssets.Item(oRefDocMat.DisplayName)
			BuyBiggest = BuyBiggest + 1
		End If
	End If
Next

 

Not entirely sure what I'm doing wrong here. Line 36 is the "Member Not Found" error.

 

This is a simplified version of my full iLogic rule. My code saves the standard content center files into a read/writable folder and edits the iProperties of the parts. All of the properties edit just fine with my iLogic, except the Material.

0 Likes
Reply
Accepted solutions (1)
393 Views
10 Replies
Replies (10)

A.Acheson
Mentor
Mentor

Hi @tbishop00 

Have you tried to set up a try catch statement here. There is a chance if the material is allready set it will error when setting the same material. It also would be good to check if the document is writable before trying to edit, add and set the material.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes

tbishop00
Contributor
Contributor

Thank you for the response. The default material for the part is "Steel, Mild," so it's not an issue with duplicating the material. A Try/Catch statement stops the error, but the material still doesn't apply to the part. I did double-check to make sure the part is writable, as

oRefDoc.MaterialAssets.Item(oRefDocMat.DisplayName).DisplayName

returns "STEEL" as expected, so the material is getting successfully copied to the part.

0 Likes

WCrihfield
Mentor
Mentor

Hi @tbishop00.  At Line 35, where you are using the Asset.CopyTo function, try capturing the resulting new 'local' Asset (or MaterialAsset) it returns to a variable, then use that variable to set the value of the PartDocument.ActiveMaterial property.  That way, you do not need to 'find' that local copy within the part's materials by its DisplayName in the process of trying to set its value.  Just one possible alternative, but not 100% sure if that change will fix the problem.  By the way, you can check if a document is editable/writable using the Document.IsModifiable property.  After seeing/hearing that you are doing a SaveAs to a writable folder, and are able to write/change other properties, I assume that is not the problem though.  Simply saving a ContentCenter member file out to a different location that is writable may not always be enough though, because it will still contain one or two PropertySets that are specific to ContentCenter stuff.  Plus, you may need to check its PartComponentDefinition.IsContentMember property to see if it is still recognized that way or not.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

tbishop00
Contributor
Contributor

I did check the IsModifiable property for the part after it is saved, and it does return True. IsContentMember returns True after the SaveAs as well. Unfortunately, capturing the new asset returned by CopyTo and applying it to the part doesn't solve the issue. I still get the Member Not Found error. The weird thing is, the documentation for the Asset Object says that I should use .Name instead of .DisplayName to input into the .Item() object. However, doing this leads to a different "The parameter is incorrect" error.

0 Likes

WCrihfield
Mentor
Mentor

Yes, working with assets by name can be complicated, due to the odd 'internal' names that get automatically generated for them.  When using the AssetsEnumerator.Item property (as in AssetsLibrary.MaterialAssets.Item), it says we can use either name.  But when using the Assets.Item property (as in PartDocument.Assets.Item), it specifically says to use the Name property of the Asset object.  It is very odd that it would not accept the result object from the CopyTo function though, so something else must be going on.  Maybe get the Document object again after the SaveAs line of code, just to make sure your oRefDoc variable is not still pointing to the 'previous/original' document.  Maybe that's what's going on...not sure.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

tbishop00
Contributor
Contributor

I added some lines to redefine oRefDoc as the newly created document object. I even verified it was the correct object by checking oRefDoc.FullFileName. Unfortunately, the error persists.

0 Likes

jnowel
Advocate
Advocate
Accepted solution

I'm not yet sure why this seems to work, but I used a new placeholder oPartDoc for the "new" part to make it work

 

Dim oPartDoc As PartDocument = ThisApplication.Documents.Open(oFolderPath & "\" & SavePartName & ".ipt", False)
oRefDocMat.CopyTo(oPartDoc)
oPartDoc.ActiveMaterial = oPartDoc.MaterialAssets.Item(oRefDocMat.DisplayName)
oPartDoc.Close(True)

 

tbishop00
Contributor
Contributor

That did it! I'm so relieved that you were able to find a solution!

0 Likes

WCrihfield
Mentor
Mentor

So, it turned out to be the document reference after all, as I suspected/mentioned at the end of Message 6.  Since you mentioned checking that out in Message 7, I assumed that was not the case.  Is it possible that the part has a custom ModelState in it (other than the original 'Primary' one)?  If so, then you may sometimes need to use the FullDocumentName, instead of just the FullFileName when using the Open method, to make sure you are working with the 'factory' version of that document, because that would be the only version you would be able to make changes to.  If you were trying to work with a 'member' version of it, it would act like ReadOnly, and you would not be able to copy a material to it, or change its material.  Just some additional thoughts.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

jnowel
Advocate
Advocate

It is indeed pretty odd behavior as when you compare the oRefDoc.FullFileName and the "new" oPartDoc..FullFileName, they are the same. So not entirely sure why oRefDoc doesn't work as it.

The following lines behave the same (since there is no ModelStates in a sample part)

 

Dim oPartDoc As PartDocument = ThisApplication.Documents.Open(oFolderPath & "\" & SavePartName & ".ipt", False)

 

Dim oPartDoc As PartDocument = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, False)


But second one seems to be better to accommodate if there is a model state 

0 Likes