Page 1 of 1

PDM API Drawing Node

Posted: Tue Jun 07, 2022 3:45 pm
by Emra
Hi everyone,

I frequently want to get a handle for the drawing of a specific part (or vice versa) in order to sync PDM variable values, but there doesn't seem to be a clean way to get a drawing hook (similar to the "Open Drawing" button for a given part) through API. Anyone want to tell me I'm wrong and there's an obvious way to do this?

For reference, I do have a functioning workaround of scanning the reference tree for immediate parent with a file extension of "slddrw" (shown below), so this isn't a blocker so much as a "why is it like this" question. It just feels like a circuitous and inefficient way to get something that should be simple - building the ref tree seems to take a long time, especially if you're processing multiple files - and I'm hoping someone on here has a better solution.

Code: Select all

    
    Function GetDrawingId(ByVal targetFile As IEdmFile17) As Integer
        Dim drawingID As Integer = Nothing
        Dim fPos As IEdmPos5 = targetFile.GetFirstFolderPosition
        Dim folder As IEdmFolder12 = targetFile.GetNextFolder(fPos)
        Dim refTree As IEdmReference11 = targetFile.GetReferenceTree(folder.ID)
        Dim rPos As IEdmPos5
        Dim refFile As IEdmFile17
        Dim ext As String
        rPos = refTree.GetFirstParentPosition2(0, False, EdmRefFlags.EdmRef_File)
        Dim parentRef As IEdmReference11
        While Not rPos.IsNull
            parentRef = refTree.GetNextParent(rPos)
            refFile = parentRef.File
            ext = Right(refFile.Name, refFile.Name.Length - refFile.Name.LastIndexOf(".") - 1)
            If ext.ToLower.Equals("slddrw") Then
                drawingID = refFile.ID
                Return drawingID
            End If
        End While

        Return drawingID
    End Function
    
Thanks in advance for any suggestions!

Re: PDM API Drawing Node

Posted: Tue Jun 07, 2022 4:42 pm
by Jordan Brown
A cheaters way that I have used before is to get the file path of the part as a string and then change the .sldprt extension to .slddrw.

As long as the part and drawing are in the same folder it works fine. If not it breaks down.

Re: PDM API Drawing Node

Posted: Tue Jun 07, 2022 5:38 pm
by Emra
Jordan Brown wrote: Tue Jun 07, 2022 4:42 pm A cheaters way that I have used before is to get the file path of the part as a string and then change the .sldprt extension to .slddrw.

As long as the part and drawing are in the same folder it works fine. If not it breaks down.
Thanks for the reply!
I might try that as a shortcut - it should work the majority of the time if the drawing exists, and then I could use the ref tree strategy as a backup if there's no .slddrw in the same folder. Doesn't solve the wasted computation of scanning the whole ref tree if the drawing doesn't exist at all yet, though... I was really hoping that there was a way to just get the drawing node directly; the info is definitely there, just not accessible via API.