- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
replace object reference in sheet
Hello,
I have a code which you run within an assembly that makes a copy of the assembly(saveAs) and puts it into a predefined drawing sheet setup. The assembly and parts are all correctly referencing the new(copied) instances, since my code also copies parts.
however it doesn't replace the object reference for my individual part drawings, which means if i generate more than one drawing, they will start interacting with each other since the drawing references the same part file (the original ones)
Imports System.Windows.Forms
Imports Inventor
Sub Main
Dim partpath As String = ThisDrawing.ModelDocument.ComponentDefinition.Parameters.Item("Location").Value
Dim pLoc = parameter("PartLocation") = partpath & "\3D\"
sheet1
sheet2
End Sub
Sub sheet1
Dim doc = ThisDoc.Document
ActiveSheet = ThisDrawing.Sheet("Sheet1:1")
End Sub
Dim oFD As FileDescriptor
Sub sheet2
Dim doc = ThisDoc.Document
ActiveSheet = ThisDrawing.Sheet("sheet1:2")
Dim viewModelDoc As String = pLoc & "Cloth.ipt"
oFD = doc.ReferencedDocumentDescriptors(1).ReferencedDocument
doc.ReplaceReference(viewModelDoc)
doc.Update()
End Sub
I have written this code within the drawing file(.dwg) which i thought would replace the reference, but i can't seem to get it to work.
my thought process was to make a sub for each specific sheet, then as the first action it will open up that sheet to get the active sheet model, replace the reference and then go to the next sheet sub.
the folder \3D\ is an automatically generated folder from the initial assembly, which has both part files and assembly files within. every time a new version of the original assembly is generated, it will create this folder at the selected director. it will also create one called \2D\, however this is for the .dwg and PDF file.
the path could look like this
c:\[PATH to selected folder]\(new folder created with drawing number name)\2D and 3D lies here\
This is the error i'm getting when running the code, the problem lies around Line 27/28, but i can't seem to figure out what im doing wrong.