Author Topic: RText causing errors with VB  (Read 4655 times)

0 Members and 1 Guest are viewing this topic.

DaveW

  • Guest
RText causing errors with VB
« on: April 18, 2006, 08:47:24 AM »
Hi All,

I have a routine that runs dview with clipping planes and then also runs the section command. The regional entities created by the sectionsolid command are then moved to an individual dynamically named and sequentially numbered layer. I have tried creating a selection set, for each Ent in thisdrawing.paperspace and few others.

Code: [Select]
Dim sHandle As String
Dim itm As AcadObject
Dim SkipPortHandle As String
Dim testvp As AcadViewports
Dim ActLayout As AcadLayout
Dim DOC As AcadDocument


   
    Set ActLayout = thisdrawing.ActiveLayout

   
    thisdrawing.ActiveSpace = acPaperSpace
    thisdrawing.MSpace = True
    Dim pviewportObj2 As AcadPViewport
    Dim testvp2 As AcadPViewport
    Dim currView As AcadPViewport
    Dim testvp3 As AcadPViewport
   
   'gets the viewport handle
    On Error Resume Next
    Set ssetObj = thisdrawing.SelectionSets.Add("prev")
    On Error GoTo 0
    ssetObj.Select acSelectionSetPrevious

 
    thisdrawing.ActivePViewport = thisdrawing.ActivePViewport
 
    SkipPortHandle = thisdrawing.ActivePViewport.Handle
 
    'gets all the layout names
    Dim Layouts As AcadLayouts, Layout As AcadLayout
    Dim LayoutName2 As AcadLayout
    Set Layouts = thisdrawing.Layouts
   
    thisdrawing.MSpace = False
   
    For Each Layout In Layouts
      If Layout.Name <> "Model" Then
        ZoomAll
        thisdrawing.ActiveLayout = Layout
        ZoomAll
       
        'ssetObj.Clear
        'ssetObj.Select acSelectionSetAll
       

            'For Each Ent In ssetObj
           
            For Each Ent In thisdrawing.PaperSpace
              If LCase(Ent.ObjectName) = "acdbviewport" Then
                 If Ent.Handle <> SkipPortHandle Then
                 
                 ZoomAll
                   If LCase(Ent.Layer) = "vports" Then
                    sHandle = Ent.Handle
                    Set itm = thisdrawing.HandleToObject(sHandle)
                   
                   
                    ZoomAll
                    Set currView = itm
                    thisdrawing.MSpace = True
                    thisdrawing.ActivePViewport = currView

                    thisdrawing.SendCommand "vplayer" & " " & "f" & " " & layername2 _
                    & vbCr & "current" & vbCr & vbCr

                    currView.Update
                   
                   End If
                 End If
              End If
            Next
     
      End If
    Next

On Error GoTo 0

thisdrawing.ActiveLayout = ActLayout


thisdrawing.MSpace = True
thisdrawing.ActivePViewport = thisdrawing.HandleToObject(SkipPortHandle)

thisdrawing.SendCommand "vplayer" & " " & "t" & " " & layername2 _
& vbCr & "current" & vbCr & vbCr


thisdrawing.SendCommand "pspace" & vbCr

thisdrawing.Regen acAllViewports


In the code above, anytime it hits any RText in paperspace it give a class error. This is a known issue to Autodesk.

Any suggestions on how to get around this? I like using RText and do not want to have to add it later or ask my customers to do that either.


Thank you,

David Wishengrad
MillLister, Inc.

PS. Alex posted this site on Woodweb, so I thought I would check it out. I still do not understand why he is not a customer yet. :) I do not really know exactly what he does and many detailiers do not have a choice of what software they use. If you read this Alex, give me a call when you get a chance. You are a pretty smart dude. I would like to undestand what your needs are.
« Last Edit: April 18, 2006, 08:58:03 AM by DaveW »

Arizona

  • Guest
Re: RText causing errors with VB
« Reply #1 on: April 18, 2006, 11:19:40 AM »
I don't know anything about the RText error, however you may have some additional errors as well. Try commenting out your on error statement and testing it.
One of the things I noticed is that you are not checking for existing selection set and deleting it. This should error if it already exists.
Something like this:

Set objSelCol = ThisDrawing.SelectionSets
   For Each objSelSet In objSelCol
      If objSelSet.Name = "MySet" Then
        objSelSet.Delete
   Exit For
      End If
   Next objSelSet
    Set objSelSet = objSelCol.Add("MySet")

Bryco

  • Water Moccasin
  • Posts: 1883
Re: RText causing errors with VB
« Reply #2 on: April 18, 2006, 12:39:27 PM »
Code: [Select]
Sub RTextErrContol()

    Dim ent As AcadEntity
        On Error GoTo Err_Control
   
    For Each ent In ThisDrawing.PaperSpace
        Debug.Print ent.ObjectName
    Next
   
Exit_Here:
    Exit Sub
Err_Control:
    Select Case Err.Number
        Case -2147221231   'Automation error
            Resume Next
        Case Else
            MsgBox Err.Description
            Err.Clear
            Resume Exit_Here
    End Select
End Sub

DaveW

  • Guest
Re: RText causing errors with VB
« Reply #3 on: April 18, 2006, 12:40:40 PM »
Yeah, I know. I have never gotten my mind around all the selections et issues, but this one I know works fine for everything. The onerror resume next is is handled by on error goto 0. I had already pulled that stuff earlier and put it back in. One of these day I will code it correctly, but it does not casue me issues becasue I know how start clean when it does not exist yet and the on errors removed. It would be a bit easier for me to do it the right way, your way, I jsut do not have the time to understand that right now. I know enough that it will click with me eventually.

Thanks for the reply,

Dave

DaveW

  • Guest
Re: RText causing errors with VB
« Reply #4 on: April 18, 2006, 12:42:31 PM »
Thanks Bryco,

but resume next will not work with a class error. It just hoses the selection set right away. I think you cannot even look at the entity in anyway or it is too late. Hence the post.
« Last Edit: April 18, 2006, 12:55:29 PM by DaveW »

Chuck Gabriel

  • Guest
Re: RText causing errors with VB
« Reply #5 on: April 18, 2006, 12:58:36 PM »
Thanks Bryco,

but resume next will not work with a class error. It just hoses the selection set right away. I think you cannot even look at the entity in anyway or it is too late. Hence the post.

Maybe this will help with that.

Quote
Error Trapping

Determines how errors are handled in the Visual Basic development environment. Setting this option affects all instances of Visual Basic started after you change the setting.

Break on All Errors — Any error causes the project to enter break mode, whether or not an error handler is active and whether or not the code is in a class module.

Break in Class Module — Any unhandled error produced in a class module causes the project to enter break mode at the line of code in the class module which produced the error.

Break on Unhandled Errors — If an error handler is active, the error is trapped without entering break mode. If there is no active error handler, the error causes the project to enter break mode. An unhandled error in a class module, however, causes the project to enter break mode on the line of code that invoked the offending procedure of the class.

DaveW

  • Guest
Re: RText causing errors with VB
« Reply #6 on: April 19, 2006, 04:28:20 PM »
Thanks Chuck, but it won't. If you guys come across this you will understand. It is just too time consuming to break out some test code to show you. I was looking for someone that was already familiar with this type of error. It is a pretty serious bug on Autodesk's end and I have yet to see any solution anywhere.

Keep up the good work,

Dave

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: RText causing errors with VB
« Reply #7 on: April 19, 2006, 04:56:57 PM »
If using selections sets then filter out the RTEXT objects. I have not found ANY sane way of working around this when iterating the Layout.Block objects. To get everything in the drawing except the RTEXT objects:
Code: [Select]
Dim oSS As AcadSelectionSet
Dim oEnt As AcadEntity
Dim iCode(0) As Integer
Dim vData(0) As Variant

iCode(0) = 0
vData(0) = "~RTEXT"

Set oSS = Me.PickfirstSelectionSet
oSS.Select acSelectionSetAll, , , iCode, vData
And FWIW, this appears to be fixed in R2007

Bryco

  • Water Moccasin
  • Posts: 1883
Re: RText causing errors with VB
« Reply #8 on: April 19, 2006, 06:04:01 PM »
That's odd, I tried it acad2006 with an rtext object and the error trap worked. Following Chucks lead (break on all errors) it didn't work then switching back again it did.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: RText causing errors with VB
« Reply #9 on: April 19, 2006, 06:24:08 PM »
Bryco, it sortof works......while it catches the error so the user isn't confronted with an error message, it does not allow any more entities to be processed once an RTEXT object is encountered. To test this draw a line, then an Rtext object, then a circle and run your macro. The Line will be output to the Immediate window but not the circle.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: RText causing errors with VB
« Reply #10 on: April 19, 2006, 11:30:07 PM »
Good point Jeff. I tried swapping the arx,lsp dll from 2000 no go. The tlb didnt register (there is one in 2000 not in 2006) maybe I should have tried regserver. I did get a crash somewhere along the line. Dbview shows it as rtext and ok. I then tried the object enabler fix Kenny mentioned thinking that since they had already fixed it that would be a good place to add the fix, but no (this just seems so mean spirited. I bet the cad bloke that makes this policy is real proud of him/herself ).
The following fullfills the line rtext circle test.
Code: [Select]
Sub RTextErrContol()

    Dim ent As AcadEntity
    Dim i As Long
    Dim MS As AcadBlock
        On Error GoTo Err_Control
    Set MS = ThisDrawing.ModelSpace
    For i = MS.Count - 1 To 0 Step -1
        Set ent = MS(i)
        Debug.Print ent.ObjectName
skip:
    Next
   
Exit_Here:
    Exit Sub
Err_Control:
    Select Case Err.Number
        Case -2147221231   'Automation error
            GoTo skip
        Case Else
            MsgBox Err.Description
            Err.Clear
            Resume Exit_Here
    End Select
End Sub