Better way to remove broken PMI Dimensions

Valued Contributor
Valued Contributor

Does anyone know of a better/faster way to clean up and remove PMI Dimensions from the models? I am currently using the following code to cycle thru the PMI.dimensions dataset but its a very time consumming task. There are approx. 100 dimnesions in total.

 

Public Sub PMI_Cleanup(ByRef xDoc As SolidEdgePart.SheetMetalDocument)

        Dim objPMI As SolidEdgeFrameworkSupport.PMI = Nothing
        Dim objDims As SolidEdgeFrameworkSupport.Dimensions = Nothing
        Dim objDim As SolidEdgeFrameworkSupport.Dimension = Nothing

        xDoc.PMI_ByModelState(PMIObj:=objPMI, PMIModelState:=SolidEdgePart.PMIModelStateConstants.seFlatModelState)

        objDims = objPMI.Dimensions
        For Each objDim In objDims
            If objDim.StatusOfDimension = 2 Then
                 objDim.Delete()
            End If
        Next

        objPMI = Nothing
        objDims = Nothing
        objDim = Nothing
        xDoc.PMI_ByModelState(PMIObj:=objPMI, PMIModelState:=SolidEdgePart.PMIModelStateConstants.seDesignModelState)

        objDims = objPMI.Dimensions
        For Each objDim In objDims
            If objDim.StatusOfDimension = 2 Then
                objDim.Delete()
            End If
        Next

        If Not (objPMI Is Nothing) Then
            Marshal.ReleaseComObject(objPMI)
            objPMI = Nothing
        End If

        If Not (objDims Is Nothing) Then
            Marshal.ReleaseComObject(objDims)
            objDims = Nothing
        End If

        If Not (objPMI Is Nothing) Then
            Marshal.ReleaseComObject(objDim)
            objDim = Nothing
        End If
    End Sub
4 REPLIES

Re: Better way to remove broken PMI Dimensions

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

 

1st recommendation would be:

 

Application.DelayCompute = True
Application.ScreenUpdating = False

....

Application.DelayCompute = False
Application.ScreenUpdating = True

 

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Better way to remove broken PMI Dimensions

Valued Contributor
Valued Contributor

Thank you very much, this has made my year. Using this has reduced the processing time from 24 mins to 8 mins. 66% increases from four lines of code is basically witch magic.

 

I know that you have put together a lot of other tutorials/samples on API programming. Which are very helpful.

 

Would there happen to be anything out there on best practices when developing Macros with performance in mind? 

 

 

Re: Better way to remove broken PMI Dimensions

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Abourgeois wrote:

Thank you very much, this has made my year. Using this has reduced the processing time from 24 mins to 8 mins. 66% increases from four lines of code is basically witch magic.


Awesome performance increase but 8 minute processing time for this task is not awesome at all.


Abourgeois wrote:

I know that you have put together a lot of other tutorials/samples on API programming. Which are very helpful.

 


Thanks for the feedback.


Abourgeois wrote:

Would there happen to be anything out there on best practices when developing Macros with performance in mind? 

 


Not that I know of off hand but you just gave me an idea for a blog post ;-).

 

Would you be able to send me a sample file? If you can, I'll spend some time looking for ways to speed up the code. This would likely help me write the blog post as well. Thanks

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Better way to remove broken PMI Dimensions

Valued Contributor
Valued Contributor

 

 

Sorry i should have provide a little more explaination as to what the macro was doing. It's not just updating the PMI Dimensions. 

 

The program is generating about 90 different unique solidedge files, 21 unique sheetmetal files, Matching Draft file with WYSIWYG dimensions and updated views to match the unique parts, 27 unique assembly files and about 15 DXF flat files. That is the part that is taking 8 mins.

 

I don't think i can send too much as its got a ton of proprietary information. However i'll see if i can create some simiple example solutions of all the different procedures that cause speed issues.

 

(Little bit of Background)

The program uses a grid system that allows a designer to lay out a product system. Then using knowledge based engineering rules it generates the CAD details

 

grid.jpgCAD.jpg

 

 

I'd love to get some feedback on a better way to update ERA exploded configurations. This allow you to update an exist exploded view so that the flow line update correctly and assembly patterns update for the view. However it a really dirty solution as it had to use commands to make it work.

 

 

 Public Sub UpdateAssembleView(ByRef xDoc As SolidEdgeAssembly.AssemblyDocument, ByRef xApp As SolidEdgeFramework.Application)

        OleMessageFilter.Register()
        xApp.DoIdle()
        xDoc.Save()
        xApp.DoIdle()

        xApp.StartCommand(10415) ' Open ERA environment
        xApp.DoIdle()

        xDoc.Configurations.Apply("explode,Solid Edge")
        xApp.DoIdle()
        Dim objCfg As SolidEdgeAssembly.Configuration = Nothing
        For p = 1 To xDoc.Configurations.Count
            If xDoc.Configurations.Item(p).Name = "explode,Solid Edge" Then
                objCfg = xDoc.Configurations.Item(p)
                objCfg.Apply()
            End If

        Next

        xApp.StartCommand(33071)

        xApp.DoIdle()
        objCfg.Update()
        xApp.DoIdle()

        xDoc.Save()
        xApp.DoIdle()
        xApp.StartCommand(10231) 'Close ERA environment
        xApp.DoIdle()


        xApp.StartCommand(33071) 'Shows all Parts
        xApp.DoIdle()
        Dim objCfg2 As SolidEdgeAssembly.Configuration = xDoc.Configurations.Item(1)
        objCfg2.Update()

        xDoc.Save()
        xApp.DoIdle()



        If Not (objCfg Is Nothing) Then
            Marshal.ReleaseComObject(objCfg)
            objCfg = Nothing
        End If
        If Not (objCfg2 Is Nothing) Then
            Marshal.ReleaseComObject(objCfg2)
            objCfg2 = Nothing
        End If
        GC.Collect()
        OleMessageFilter.Revoke()
    End Sub

 

Also if there is a faster way to do Occurance deleting from a assembly that would also make life better as well. 

 

  For d = 1 To objDoc1.Occurrences.Count
                    If d > objDoc1.Occurrences.Count Then
                        Exit For
                    End If
                    objOccurence = objDoc1.Occurrences.Item(d)
                    strIndex = Split(objOccurence.Name, ":")
                    strFilename = Split(objOccurence.Name, ".")
                    If ((strFilename(0) = "264488") Then ' Spacer bar part number
                        objOccurence.Delete()
                        d = d - 1
                        objApplication.DoIdle()
                    End If
                Next