standardobjectfactory not working

standardobjectfactory not working

tobias_wiesendanger
Advocate Advocate
438 Views
5 Replies
Message 1 of 6

standardobjectfactory not working

tobias_wiesendanger
Advocate
Advocate

I recently found this great class called standardobjectfactory and was under the impression I can create a new "document" object and then use ilogic function as if that was the active document.

So I tried something like this:

Dim bomTable As PartsList
If (ThisDrawing.Document.Sheets.Item(1).PartsLists.Count > 0) Then
bomTable = ThisDrawing.Document.Sheets.Item(1).PartsLists.Item(1)
End If

' check each row if the document belonging to this row has a property called settings.propertyToCheck and the value is y
Dim row As PartsListRow
For Each row In bomTable.PartsListRows
If (row.ReferencedFiles.Count > 0) Then ' if count = 0 = virtual
docObj = StandardObjectFactory.Create(row.ReferencedFiles.Item(1).DocumentDescriptor.ReferencedDocument)
Logger.Debug(docObj.ThisDrawing.Name )
Logger.Debug(docObj.ThisDocument.FileName)
End If
Next



To test this code. Create a drawing from an assembly and place a partslist.

Both logger function throw an error of Name / FileName is not a public member, but they show up in intellisense just fine. Am I understanding something wrong? Is that something that should work? For what is StandardObjectFactory if not for something like this. In the end I would like to access the properties as usual.

regards

Tobias

0 Likes
Accepted solutions (1)
439 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @tobias_wiesendanger.  The StandardObjectFactory object (represents an Interface) is not for creating a document object.  You have to input a Document object into its Create method, in order to get an IStandardObjectProvider Type object.  Then that object you get in return (the IStandardObjectProvider) is used as a document reference to start many of the other iLogic shortcut snippets from, as a way to ensure which document that snippet will be focused on as the document they will be working with.  So, for example, lets say you have an assembly open, and are looping through tons of either referenced documents or looping through components.  You can use this to make sure your iLogic shortcut snippet is focused on the one specific document that you want it to be focused on, and not some other (mysterious/unknown) document.  Here is a little bit of code I wrote for myself, as a reminder:

 

oDoc = ThisDoc.Document
SOP = StandardObjectFactory.Create(oDoc)
oModel = SOP.ThisDrawing.ModelDocument
oPropVal = SOP.iProperties.Value("Project", "Description")
oList = SOP.MultiValue.List("ParamName")
oParamVal = SOP.Parameter("ParamName")
oSMLength = SOP.SheetMetal.FlatExtentsLength
SOP.Sketch.Redefine("SketchName", "PlaneName", "OriginName", "AxisName")
SOP.WorkPlane.FlipNormal("WPlaneName", "RefAxisName")

 

You first get a reference to the document object that you want to work with.  Then you input that document into this Create command to get the object I Mentioned above.  Then you use that object you just created as a starter for whichever iLogic shortcut snippet you want, to ensure that the snippet will be referencing that specific document as its source.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

tobias_wiesendanger
Advocate
Advocate

Ok I phrased that really wrong, but what you are describing is what I understood. Isnt that exactly what I'm doing? Im getting the reference from a partslistrow which is a document and I am using that as an input for the factory. So after that I should be able to call iLogic functions on this instance. 

0 Likes
Message 4 of 6

tobias_wiesendanger
Advocate
Advocate
Accepted solution
Dim bomTable As PartsList
If (ThisDrawing.Document.Sheets.Item(1).PartsLists.Count > 0) Then
bomTable = ThisDrawing.Document.Sheets.Item(1).PartsLists.Item(1)
End If

' check each row if the document belonging to this row has a property called settings.propertyToCheck and the value is y
Dim row As PartsListRow
For Each row In bomTable.PartsListRows
If (row.ReferencedFiles.Count > 0) Then ' if count = 0 = virtual
	Dim docObj = StandardObjectFactory.Create(row.ReferencedFiles.Item(1).DocumentDescriptor.ReferencedDocument)
	Logger.Debug(docObj.ThisDocument.FileName)
End If
Next

Dim was missing before the docObj. Thats why it didnt work. Thanks @MjDeck 

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

Your Logger line using 'ThisDrawing' would not work, because it is meant to be working with a DrawingDocument type document, and you created the 'provider' object based on a 'model' type document from that PartsListRow.  At least that's my thoughts/opinion on why that line did not work correctly.  The other thing that may be causing a problem, but I am not so sure about in this situation, is that both of those Logger lines are potentially dealing with other document references.  Because the terms 'ThisDoc', 'ThisDrawing', & 'ThisAssembly' (as well as the 'ThisDocument' phrase found here, I believe) are all used as 'original' pointers to a document object, based on a block of code somewhere written by the folks at Autodesk, and work differently in different situations.  So they may be trying to point to other documents, instead of the 'input' document.  There are definitely some areas of 'grey' in there that we can not fully understand without knowing the source code behind them, which is hidden somewhere within the installation files.

 

If all you wanted to do in that situation was to log the file name of the Document object that you obtained from that row of the parts list, that would likely be more efficiently done by defining the variable as a Document Type object instead.  The Document object has the DisplayName, FullFileName, & FullDocumentName properties.

 

Edit:  Ok.  I see that Mike helped clear up the issue when using the 'ThisDocument' reference.  I have never used that specific property of it before, so I wasn't sure how it might be defined in a situation like this.  Mike is the mastermind behind a lot of those iLogic only terms.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6

tobias_wiesendanger
Advocate
Advocate

You are correct about ThisDrawing not working. This is to be expected. That was added after I encountered the error.

The logs are just a sample. This allows some great things like adding a property to a partlist row referenced document by using the simple ilogic syntax.

 

Dim docObj = StandardObjectFactory.Create(row.ReferencedFiles.Item(1).DocumentDescriptor.ReferencedDocument)
docObj.iProperties.Value("Custom", "Test999")="9999"

 

The ThisDocument seams to behave correctly.