Better way to deal with INSBASE!

Discussion in 'AutoCAD' started by Oberer, Jan 21, 2005.

  1. Oberer

    Oberer Guest

    I'm not sure what or why INSBASE changes, but it's really causing some confusion at the office.

    When xrefing/inserting a drawing with INSBASE <> 0,0,0, the dwg won't xref/insert correctly at 0,0,0.

    There has to be a better way to deal with it than this!
    Show me the way :)

    Code:
    Private Sub AcadDocument_BeginSave(ByVal FileName As String)
    ThisDrawing.SendCommand "ucs" & vbCr & "W" & vbCr
    ThisDrawing.SendCommand "insbase" & vbCr & "0,0,0" & vbCr
    ThisDrawing.SendCommand "ucs" & vbCr & "P" & vbCr
    End Sub
    
     
    Oberer, Jan 21, 2005
    #1
  2. Oberer

    Gordon Price Guest

    Even the approach you show might not work when a user does a Wblock and
    chooses a base point. Currently, the new DWG has the same 0,0 as the source
    DWG, and INSBASE is used to force the insertion point. I consider this a
    functional bug, and I think when you WBlock and choose a base point, that
    point should be at 0,0 in the resulting DWG.

    Best,
    Gordon
     
    Gordon Price, Jan 21, 2005
    #2
  3. Oberer

    Kevin Terry Guest

    Dim aBase(0 To 2) As Double
    aBase(0) = 0: aBase(1) = 0: aBase(2) = 0
    ThisDrawing.SetVariable "INSBASE", aBase


    Kevin


    xref/insert correctly at 0,0,0.
     
    Kevin Terry, Jan 24, 2005
    #3
  4. Oberer

    Oberer Guest

    Gordon,
    Thanks, but the problem is not with wblocks, it's inserting and XREFing that dwg into others.
    (Example: Dwg A is saved with a WCS INSBASE of 10,10,10.
    Dwg B has an INBASE of 0,0,0. While in DWG A, i xref in B, which works fine. I then open B and XREF A and i'm off by the 10,10,10. To avoid this problem/consfusion i was hoping to restore the WCS INSBASE to 0,0,0 when the document closes. However, I crash ACAD pretty easily placing code in these events, so I've stayed away from them)

    Kevin Terry,
    You're code is essentially what I had, however, the dwg must be in WCS for this work (which is why i resorted to send command)

    (This is what I'd started with a while ago. I realized that if the dwg's not in WCS, it's worthless!)

    Code:
    ' When opening a dwg, check the BASE point for 0,0,0
    ' warn user if it's not 0,0,0
    
    Private Sub AcadDocument_Activate()
    Dim varData As Variant
    Dim x As Double, y As Double, z As Double
    Dim i As Integer
    Dim oLayout As AcadLayout
    Dim strMSG As String
    Dim intOrigLAYOUTREGENCTL As Integer
    
    'Dim a As clsAcadEvents
    'Set myEvents = New clsAcadEvents
    ' if the dwg is in paper space, we need to temporarily
    ' switch to model to verify the "real" base point
    ' (the one that seems to affect XREF and INSERT)
    
    If ThisDrawing.ActiveSpace = acPaperSpace Then
    Set oLayout = ThisDrawing.ActiveLayout
    intOrigLAYOUTREGENCTL = ThisDrawing.GetVariable("LAYOUTREGENCTL")
    ThisDrawing.SetVariable "LAYOUTREGENCTL", 0
    ThisDrawing.ActiveSpace = acModelSpace
    End If
    
    varData = ThisDrawing.GetVariable("INSBASE")
    
    x = Round(varData(0), 1)
    y = Round(varData(1), 1)
    z = Round(varData(2), 1)
    If (x + y + z) <> 0 Then
    ' build message to display
    strMSG = "WARNING: Model Space BASE was-> " & vbNewLine & _
    "X:" & varData(0) & " Y:" & varData(1) & " Z:" & varData(2) & _
    "Set Model Space BASE to 0,0,0"
    'reset base
    varData(0) = 0: varData(1) = 0: varData(2) = 0
    ' reset variable
    ThisDrawing.SetVariable "INSBASE", varData
    
    End If
    
    ' if dwg was saved on a layout, restore it
    If Not oLayout Is Nothing Then
    ThisDrawing.ActiveLayout = oLayout
    ThisDrawing.SetVariable "LAYOUTREGENCTL", intOrigLAYOUTREGENCTL
    End If
    
    ' if valid, display message
    If strMSG <> vbNullString Then
    MsgBox strMSG, vbInformation, "MSpace BASE CHANGED"
    End If
    
    
    End Sub
     
    Oberer, Jan 24, 2005
    #4
  5. Oberer

    Oberer Guest

    Gordon,
    Thanks, but the problem is not with wblocks, it's inserting and XREFing that dwg into others.
    (Example: Dwg A is saved with a WCS INSBASE of 10,10,10.
    Dwg B has an INBASE of 0,0,0. While in DWG A, i xref in B, which works fine. I then open B and XREF A and i'm off by the 10,10,10. To avoid this problem/consfusion i was hoping to restore the WCS INSBASE to 0,0,0 when the document closes. However, I crash ACAD pretty easily placing code in these events, so I've stayed away from them)

    Kevin Terry,
    You're code is essentially what I had, however, the dwg must be in WCS for this work (which is why i resorted to send command)

    (This is what I'd started with a while ago. I realized that if the dwg's not in WCS, it's worthless!)

    Code:
    ' When opening a dwg, check the BASE point for 0,0,0
    ' warn user if it's not 0,0,0
    
    Private Sub AcadDocument_Activate()
    Dim varData As Variant
    Dim x As Double, y As Double, z As Double
    Dim i As Integer
    Dim oLayout As AcadLayout
    Dim strMSG As String
    Dim intOrigLAYOUTREGENCTL As Integer
    
    'Dim a As clsAcadEvents
    'Set myEvents = New clsAcadEvents
    ' if the dwg is in paper space, we need to temporarily
    ' switch to model to verify the "real" base point
    ' (the one that seems to affect XREF and INSERT)
    
    If ThisDrawing.ActiveSpace = acPaperSpace Then
    Set oLayout = ThisDrawing.ActiveLayout
    intOrigLAYOUTREGENCTL = ThisDrawing.GetVariable("LAYOUTREGENCTL")
    ThisDrawing.SetVariable "LAYOUTREGENCTL", 0
    ThisDrawing.ActiveSpace = acModelSpace
    End If
    
    varData = ThisDrawing.GetVariable("INSBASE")
    
    x = Round(varData(0), 1)
    y = Round(varData(1), 1)
    z = Round(varData(2), 1)
    If (x + y + z) <> 0 Then
    ' build message to display
    strMSG = "WARNING: Model Space BASE was-> " & vbNewLine & _
    "X:" & varData(0) & " Y:" & varData(1) & " Z:" & varData(2) & _
    "Set Model Space BASE to 0,0,0"
    'reset base
    varData(0) = 0: varData(1) = 0: varData(2) = 0
    ' reset variable
    ThisDrawing.SetVariable "INSBASE", varData
    
    End If
    
    ' if dwg was saved on a layout, restore it
    If Not oLayout Is Nothing Then
    ThisDrawing.ActiveLayout = oLayout
    ThisDrawing.SetVariable "LAYOUTREGENCTL", intOrigLAYOUTREGENCTL
    End If
    
    ' if valid, display message
    If strMSG <> vbNullString Then
    MsgBox strMSG, vbInformation, "MSpace BASE CHANGED"
    End If
    
    
    End Sub
    
     
    Oberer, Jan 24, 2005
    #5
  6. Oberer

    Gordon Price Guest

    I guess my point is the only time I have ever seen INSBASE be anything but
    0,0,0 is when a DWG is created with Wblock and origin is set to a pick
    point, rather than 0,0,0. And once INSBASE is set to 0,0,0 again, it should
    (in theory) stay that way. If not, you might want to check for in-house code
    that is doing this, or a misguided user doing it. I found that it happened
    rarely enough, and was solvable by manual correction and user training, and
    didn't bother to create an automation tool to address the issue. Just my
    $0.02.

    Best,
    Gordon
     
    Gordon Price, Jan 25, 2005
    #6
  7. Oberer

    Oberer Guest

    KT, as you can see, i tried this as well from my second post
    Code:
    varData = ThisDrawing.GetVariable("INSBASE")
    
    x = Round(varData(0), 1)
    y = Round(varData(1), 1)
    z = Round(varData(2), 1)
    If (x + y + z) <> 0 Then
    ' build message to display
    strMSG = "WARNING: Model Space BASE was-> " & vbNewLine & _
    "X:" & varData(0) & " Y:" & varData(1) & " Z:" & varData(2) & _
    "Set Model Space BASE to 0,0,0"
    'reset base
    varData(0) = 0: varData(1) = 0: varData(2) = 0
    ' reset variable
    ThisDrawing.SetVariable "INSBASE", varData
    
    I'm thinking that I mentioned this works IF the dwg is in the world ucs, otherwise setting the ucs base is useless...
     
    Oberer, Feb 10, 2005
    #7
  8. Oberer

    Kevin Terry Guest

    yes you're right, i have the same problem here with that code :(

    sorry i can't be of more help

    Kevin

    otherwise setting the ucs base is useless...
     
    Kevin Terry, Feb 14, 2005
    #8
  9. You might try the Origin property.
     
    Mark Johnston, Feb 17, 2005
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.