- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
iLogic to Retrieve Path And File of a Model on a Drawing
Hi Forum,
Does anyone know how I get the path and file of a model inside an idw?
Best regards,
Felix Cortes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, look at the following code maybe I can help you. With it you can access the model document from the drawing view.
I used a view selection method. You can select the view through the item or otherwise if you need it.
I hope this helps. regards
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Seleccione Vista") If oView Is Nothing Then Exit Sub Dim oModelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument Dim oViewModelName As String = oModelDoc.DisplayName Dim oFullFilePath As String = oModelDoc.FullFileName Dim oFolderPath As String = Left(oFullFilePath, (InStrRev(oFullFilePath, "\", - 1, vbTextCompare) - 1)) MessageBox.Show("DisplayName: " & oViewModelName) MessageBox.Show("FullFilename: " & oFullFilePath) MessageBox.Show("FolderPath: " & oFolderPath )
Please accept as solution and give likes if applicable.
I am attaching my Upwork profile for specific queries.
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Felix,
You can use the ModelDocument code snippet from Advanced Drawing API. This will retrieve the model associated to the drawing. If there's more than one model, it will pick the first one. If there is more than one model, you can use the ModelDocument(View) snippet and this will let you define the view name and it will retrieve the model associated to the view. Once the model is retrieved, which is a document object, you can get different properties such as Displayname, FillFileName, etc.
So the code will look something like this. Hope that helps.
DanV
doc = ThisDrawing.ModelDocument 'from the Model Document snippet MessageBox.Show(doc.FullDocumentName) 'use FullDocumentName to get path & file name MessageBox.Show(doc.DisplayName) 'use to get the file name only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi DanV,
I would like to add a sheet, based on an existing sheet format, for the part/assembly in my drawing.
The snippet you suggest fetches the file path, but how would I insert it into the code below, to fulfill the function I require? Any guidance would be appreciated.
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
'Set a reference to the sheet format named "C size, 4 view"
Dim oFormat As SheetFormat
Try
oFormat = oDrawDoc.SheetFormats.Item("C size, 4 view")
Catch
MessageBox.Show("Error: C size, 4 view might not exist.", "iLogic")
Return
End Try
'Open the model document invisible
Dim oModel As Document
oModel = ThisApplication.Documents.Open("C:\TEMP\block.ipt", False)
'Create a new sheet based on the sheet format using the specified model
Dim oSheet As Sheet
oSheet = oDrawDoc.Sheets.AddUsingSheetFormat(oFormat, oModel)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello tjvz85,
I'm not sure if I understand your request. Can you give me more detail as to what you are looking to do?
The code that you have there will create a new sheet using the "C Size, 4 View" sheet format. It will use the block.ipt as the model for the sheet format. So when it first starts, there is no model yet. It's a blank sheet therefore this is no model path to retrieve. Then it will look for the block.ipt in C:\temp and use that as the model for the sheet format. The block.ipt is hard coded into the rule. Are you asking if you can be prompted for the model? If so, you can do something like this. Hopefully that's what you are looking for. If not, repost and let's try again.
Dan
' Set a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument 'Set a reference to the sheet format named "C size, 4 view" Dim oFormat As SheetFormat Try oFormat = oDrawDoc.SheetFormats.Item("C size, 4 view") Catch MessageBox.Show("Error: C size, 4 view might not exist.", "iLogic") Return End Try Dim openfiledia As New OpenFileDialog() Dim strModelFile As String With openfiledia .Filter = "Autodesk Inventor Part|*.ipt|Autodesk Inventor Assembly|*.iam" .Multiselect = False 'if user cancelled, exit this subroutine If .ShowDialog() = DialogResult.Cancel Then Exit Sub End If strModelFile = .FileName End With 'Open the model document invisible Dim oModel As Document oModel = ThisApplication.Documents.Open(strModelFile, False) 'Create a new sheet based on the sheet format using the specified model Dim oSheet As Sheet oSheet = oDrawDoc.Sheets.AddUsingSheetFormat(oFormat, oModel)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi DanV,
Thanks for your response.
My goal is this:
We create new drawings for every part or assembly and we use the same template.
For parts, there will only be one sheet per drawing, but for assemblies, we add a sheet for a production specific partslist.
I would like to add the sheet for the assembly file that is on the first sheet.
I have code (written by Curtis Waguespack) to check the Views on the sheet to see whether a part or assembly has been placed and then call a specific function. But I wanted to see if I can rather just check the file placed in the drawing, determine whether it is a part or assembly, and then place the second sheet if it is an assembly.
The code below checks the views, if they are of an assembly, it checks if the model file has a Design view named colour and the writes the colour to a custom iproperty that I use in the title block. If we can't just verify whether the referenced file is an assembly, I would like to run through the views and place the sheet, based on existing Sheet Format.
Thank you in advance for your further assistance.
Sub Main
' Get the active drawing document.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
Dim oViews As DrawingViews
Dim oView As DrawingView
'get the collection of view on the sheet
oViews = oSheet.DrawingViews
' Iterate through the views on the sheet
For Each oView In oViews
Dim docDesc As DocumentDescriptor
docDesc = oView.ReferencedDocumentDescriptor
' Verify that the drawing view is of an assembly.
If docDesc.ReferencedDocumentType <> kAssemblyDocumentObject Then
Continue For
End If
' Get the component definition for the assembly.
Dim asmDef As AssemblyComponentDefinition
asmDef = docDesc.ReferencedDocument.ComponentDefinition
'define view rep collection
Dim oViewReps As DesignViewRepresentations
oViewReps = asmDef.RepresentationsManager.DesignViewRepresentations
oColourViewRepFound = False
For Each oViewRep In oViewReps
If oViewRep.Name = "Colour" Then
oColourViewRepFound = True
End If
Next
If oColourViewRepFound = True Then
Call ProcessAssemblyColor(oView, asmDef.Occurrences)
End If
Next
End Sub
Private Sub ProcessAssemblyColor(drawView As DrawingView, _
Occurrences As ComponentOccurrences)
' Iterate through the current collection of occurrences.
Dim occ As ComponentOccurrence
For Each occ In Occurrences
' Check to see if this occurrence is a part or assembly.
If occ.DefinitionDocumentType = kPartDocumentObject Then
' Get the render style of the occurrence.
Dim color As RenderStyle
Dim sourceType As StyleSourceTypeEnum
color = occ.GetRenderStyle(sourceType)
If color.name IsNot Nothing Then
iProperties.Value("Custom", "Lackierung") = color.name
Exit For
End If
End If
Next
End Sub