- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @op_thorsager. There is so much here that seems wrong or questionable, I don't even know where to start. In the first part of your code you are attempting to access two different Parameters, one named "Location", and one named "PartLocation". You appear to be getting the initial 'path' information from the one named "Location", but then the next line of code is confusing me. Are you attempting to set the value of 'pLoc' from the parameter named "PartLocation" or are you trying to set the value of the parameter named "PartLocation"? You should not have two equals signs (=) in the same line of code. What is your intent with that line of code? Should the 'pLoc' variable be getting its value from the parameter named "Location" or from the parameter named "PartLocation"? Do you need to set the value of the parameter named "PartLocation" to the same value as the 'pLoc' variable?
Your 'pLoc' variable is not 'shared', like your 'oFD' variable is, therefore, when you are trying to use it within your 'sheet2' Sub routine, it is not only undefined, it also does not have a value yet (as far as that sub routine knows).
In your 'sheet2' sub routine, you are trying to set your 'oFD' variable's value to a Document type object (ReferencedDocument), instead of a FileDescriptor, therefore it is throwing an error. Then on the very next line of code, you are trying to use your 'doc' variable, instead of the 'oFD' variable with the 'ReplaceReference' method, which is only available to the FileDescriptor Type object, so that too would throw an error.
If the active drawing document has more than one referenced model document, then you may need to loop through each DrawingView on each sheet of the drawing, to replace the referenced model of each view, instead of trying to replace just the first file reference of the entire drawing. Otherwise you may need to loop through each referenced document in the drawing documents referenced documents collection, instead of just its first one (if more than one).
I also attempted to correct the line of code stetting the active sheet of the drawing, but I am not sure what your intent was in having an entire sub routine just for activating a specific sheet of the drawing.
Below is a version of your code which I attempted to correct, with my limited understanding of your intents, and before getting the above questions answered yet.
Imports System.Windows.Forms
Imports Inventor
Sub Main
oDDoc = ThisDoc.Document
Dim oModelDoc As Document = ThisDoc.ModelDocument
Dim oCD As ComponentDefinition = oModelDoc.ComponentDefinition
Dim oParams As Inventor.Parameters = oCD.Parameters
'??? which parameter is it supposed to be getting the correct path from ???
'??? is this also supposed to be setting the value of one of these parameters ???
Dim partpath As String = oParams.Item("Location").Value
pLoc = partpath & "\3D\"
oParams.Item("PartLocation").Value = pLoc
sheet1
sheet2
End Sub
'shared variables - available in every routine
Dim oDDoc As DrawingDocument
Dim pLoc As String
Dim oFD As FileDescriptor
Sub sheet1
oDDoc.Sheets.Item("Sheet1:1").Activate
End Sub
Sub sheet2
oDDoc.Sheets.Item("sheet1:2").Activate
Dim viewModelDoc As String = pLoc & "Cloth.ipt"
oFD = oDDoc.ReferencedDocumentDescriptors.Item(1).ReferencedFileDescriptor
oFD.ReplaceReference(viewModelDoc)
oDDoc.Update()
End Sub
Wesley Crihfield
(Not an Autodesk Employee)