Author Topic: prbolems with find objects in autodesk using VB.NET  (Read 1420 times)

0 Members and 1 Guest are viewing this topic.

inneedofhelp

  • Guest
prbolems with find objects in autodesk using VB.NET
« on: December 12, 2011, 02:34:00 PM »
i am openining and loading ACAD drawing automatically from the code. this is to be a standalone exe that loads the files and then tags them with a new block item. i get so far as opening acad and a drawing then it says failed to get object. sometimes it will go through the for loop once and then it will just fail to open the next drawing.. which is weird.
Code: [Select]
       MyDwgDoc = MyAcad.Documents.Open(filepath)
            If Err.Number = -2145320924 Then
                DataGridView3.Rows(ridx).Cells(8).Value = "No File"
            End If
            On Error GoTo Err_ProcessAutoCAD
            booChange = False
            '**  **  **

            For Each MyObj In MyDwgDoc.ModelSpace
                booMfgTag = False
                '** Find all Titleblocks
                If MyObj.ObjectName = "AcDbBlockReference" Then
                If MyObj.Name = "MSP-B-BORDER" Then
                    XOffset = (12 + 47 / 64) - 1.875
                    DScale = 1.0#
                    booMfgTag = True
                ElseIf MyObj.Name = "MSP-D-BORDER" Then
                    XOffset = (24 + 29 / 32) - 3.75
                    DScale = 2.0#
                    booMfgTag = True
                ElseIf MyObj.Name = "B-BORDER" Then
                    XOffset = (12 + 47 / 64) - 1.875
                    DScale = 1.0#
                    booMfgTag = True
                ElseIf MyObj.Name = "D-BORDER" Then
                    XOffset = (24 + 29 / 32) - 3.75
                    DScale = 2.0#
                    booMfgTag = True
                ElseIf MyObj.Name = "BLOCK1" Then
                    XOffset = (24 + 29 / 32) - 3.75
                    DScale = 2.0#
                    booMfgTag = True
                End If
                    If booMfgTag Then
                        TBInsrtPt = MyObj.InsertionPoint
                        '** Set-up and insert MfgTag
                        InsertPnt(0) = TBInsrtPt(0) + XOffset * MyObj.XScaleFactor
                        InsertPnt(1) = TBInsrtPt(1)
                        InsertPnt(2) = TBInsrtPt(2)
                        MTObj = MyDwgDoc.ModelSpace.InsertBlock(InsertPnt, strBlock, _
                            MyObj.XScaleFactor * DScale, MyObj.YScaleFactor * DScale, MyObj.ZScaleFactor * DScale, 0.0#)
                        '** Change the attributes of the new block
                        RetVal = MTObj.GetAttributes
                        If IsDBNull(DataGridView3.Rows(ridx).Cells(4).Value) Then
                            DataGridView3.Rows(ridx).Cells(4).Value = " "
                        End If
                        If IsDBNull(DataGridView3.Rows(ridx).Cells(5).Value) Then
                            DataGridView3.Rows(ridx).Cells(5).Value = " "
                        End If
                        If IsDBNull(DataGridView3.Rows(ridx).Cells(6).Value) Then
                            DataGridView3.Rows(ridx).Cells(6).Value = " "
                        End If
                        If IsDBNull(DataGridView3.Rows(ridx).Cells(7).Value) Then
                            DataGridView3.Rows(ridx).Cells(7).Value = " "
                        End If
                        For intI = LBound(RetVal) To UBound(RetVal)
                            If RetVal(intI).TagString = "CSJOB" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(3).Value
                            If RetVal(intI).TagString = "LOCATION" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(4).Value
                            If RetVal(intI).TagString = "DESCRIPTION" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(5).Value
                            If RetVal(intI).TagString = "RESPONSIBLE1" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(6).Value
                            If RetVal(intI).TagString = "RESPONSIBLE2" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(7).Value
                            If RetVal(intI).TagString = "QTY" Then RetVal(intI).TextString = DataGridView3.Rows(ridx).Cells(1).Value
                        Next intI
                        booChange = True
                    End If
                End If
            Next