Author Topic: Block Unmirror  (Read 2483 times)

0 Members and 1 Guest are viewing this topic.

jjs

  • Guest
Block Unmirror
« on: December 21, 2006, 06:08:59 PM »
So I found this post by 808 \/\/4#R
http://www.theswamp.org/index.php?topic=6791.msg83800#msg83800

I tried it on a drawing that I have been testing different routines on. Most of the blocks worked, but some did not. Odd. I am also going to need to add a rotate attribute rotation to 0 code section. I will ask for help when I get stuck.

Unless of course 808 has tidied it up since the original posting.

well 808?

Arizona

  • Guest
Re: Block Unmirror
« Reply #1 on: December 21, 2006, 07:13:04 PM »
Hi Jeremie,

Bob has not been around for awhile :-(

jjs

  • Guest
Re: Block Unmirror
« Reply #2 on: December 21, 2006, 07:26:47 PM »
After I posted I went back and reread his post and noticed it said guest under his name. No fun giving a guy a hard time if he does not even see it.

I will try to contact him by other means, see if I can drag him back here.

thanks for the heads up.

Arizona

  • Guest
Re: Block Unmirror
« Reply #3 on: December 21, 2006, 07:33:15 PM »
Good to see you and Merry Christmas! :-)

jjs

  • Guest
Re: Block Unmirror
« Reply #4 on: December 21, 2006, 10:04:46 PM »
Well, I took 808's good start and made it better. The attributes now are the correct rotation angle and the correct location. Took me a while to figure it out because the insertion point property is not used for attributes that are not left, fit, or aligned for their alignment property.
Hope this helps others. Eventually need to do the unmirY. Oh and I never updated the paperspace part. But who draws and mirrors in paperspace?

Code: [Select]
Option Explicit

Public Sub UnMirror()
On Error GoTo ErrorControl
 
  Dim strSet As String
  Dim intGroup() As Integer
  Dim varGroup() As Variant
  Dim varAtts As Variant
  Dim objSelSet As AcadSelectionSet
  Dim objSelSets As AcadSelectionSets
  Dim strBlkName As String
  Dim PI As Double
  Dim strSetName As String
  Dim objBlkRef As AcadBlockReference
  Dim objEnt As AcadEntity
  Dim intCnt As Integer
 
  PI = (Atn(1) * 4)
  Set objSelSets = ThisDrawing.SelectionSets
  strSetName = 1
  ReDim intGroup(0)
  ReDim varGroup(0)
  intGroup(0) = 0
  varGroup(0) = "insert"

BlockName:
  strBlkName = ThisDrawing.Utility.GetString(True, "Block to unmirror [All, Select, <default block name goes here>]:")
  If strBlkName = "" Or Left(strBlkName, 1) = " " Then
    ReDim Preserve intGroup(0 To 1)
    ReDim Preserve varGroup(0 To 1)
    intGroup(1) = 2
    varGroup(1) = "defaultblockname"
  ElseIf StrComp(strBlkName, "a", vbTextCompare) = 0 Or StrComp(strBlkName, "all", vbTextCompare) = 0 Then
    ReDim Preserve intGroup(0 To 1)
    ReDim Preserve varGroup(0 To 1)
    intGroup(1) = 2
    varGroup(1) = "*"
  ElseIf StrComp(strBlkName, "s", vbTextCompare) = 0 Or StrComp(strBlkName, "sel", vbTextCompare) = 0 Or StrComp(strBlkName, "select", vbTextCompare) = 0 Then
    KillSet strSetName
    Set objSelSet = objSelSets.Add(strSetName)
    objSelSet.SelectOnScreen intGroup, varGroup
    ReDim intGroup(0 To (objSelSet.Count) + 1)
    ReDim varGroup(0 To (objSelSet.Count) + 1)
    intGroup(0) = -4
    varGroup(0) = "<or"
    intGroup((objSelSet.Count) + 1) = -4
    varGroup((objSelSet.Count) + 1) = "or>"
   
    For intCnt = 1 To objSelSet.Count
      If TypeOf objSelSet.Item(intCnt - 1) Is AcadBlockReference Then
        Set objBlkRef = objSelSet.Item(intCnt - 1)
        intGroup(intCnt) = 2
        varGroup(intCnt) = objBlkRef.Name
      End If
    Next intCnt
  Else
    ReDim Preserve intGroup(0 To 1)
    ReDim Preserve varGroup(0 To 1)
    intGroup(1) = 2
    varGroup(1) = strBlkName
  End If
 
  KillSet strSetName
  Set objSelSet = objSelSets.Add(strSetName)
  objSelSet.Select acSelectionSetAll, , , intGroup, varGroup
 
  If objSelSet.Count > 0 Then
    GoTo FollowTheRabbit
  Else
    ThisDrawing.Utility.Prompt vbCrLf & "**No Blocks Selected**" & vbCrLf
    GoTo ExitHere
  End If
   
FollowTheRabbit:
  Dim dblMSpc As Double
  Dim dblPSpc As Double
  Dim dblRotRad As Double
  Dim dblrotrad180 As Double
  Dim dblRotDeg As Double
  Dim dblScale(0 To 2) As Double
  Dim dblInsPt(0 To 2) As Double
  Dim objNewRef As AcadBlockReference
  Dim varOldAtt As Variant
  Dim varNewAtt As Variant
 
  dblMSpc = ThisDrawing.ModelSpace.ObjectID
  dblPSpc = ThisDrawing.PaperSpace.ObjectID
 
    For Each objEnt In objSelSet
      If TypeOf objEnt Is AcadBlockReference Then
        Set objBlkRef = objEnt
        If objBlkRef.XScaleFactor < 0 Then
          dblInsPt(0) = objBlkRef.InsertionPoint(0)
          dblInsPt(1) = objBlkRef.InsertionPoint(1)
          dblInsPt(2) = objBlkRef.InsertionPoint(2)
          dblScale(0) = objBlkRef.XScaleFactor * -1
          dblScale(1) = objBlkRef.YScaleFactor
          dblScale(2) = objBlkRef.ZScaleFactor
          dblRotRad = objBlkRef.Rotation
          '*******************************
          dblRotDeg = (dblRotRad * 180) / PI
          'If dblRotDeg > 90 Then MsgBox "dblrotdeg above 90 radians = " & dblRotRad
          Debug.Print "dblRotRad " & dblRotRad
          'Select Case dblRotRad
          'Case 0 To (PI * 120) / 180
          '  Debug.Print "dblRotRad between 0 and 90 =" & dblRotRad
              dblrotrad180 = (PI * 180) / 180
              dblRotRad = dblRotRad + dblrotrad180
          'Case (PI * 120) / 180 To (PI * 360) / 180
          '  Debug.Print "dblRotRad between 120 and 330 =" & dblRotRad
          '    dblrotrad180 = (PI * 180) / 180
          '    dblRotRad = dblRotRad + dblrotrad180
          'Case Else
         
         '   Debug.Print "dblRotRad NOT BETWEEN 0 AND 90 =" & dblRotRad
          'End Select
         
          '*******************************
'          dblRotDeg = (dblRotRad * 180) / PI
'          Debug.Print "dblRotDeg " & dblRotDeg
'          If dblRotDeg > 120 And dblRotDeg < 330 Then
'            dblRotDeg = dblRotDeg + 180
'            If dblRotDeg > 360 Then
'              dblRotDeg = dblRotDeg - 360
'            End If
'            dblRotRad = (PI * dblRotDeg) / 180
'          End If
          If objBlkRef.OwnerID = dblMSpc Then
            Set objNewRef = ThisDrawing.ModelSpace.InsertBlock(dblInsPt, objBlkRef.Name, dblScale(0), dblScale(1), dblScale(2), dblRotRad)
            If objNewRef.HasAttributes Then
              varOldAtt = objBlkRef.GetAttributes
              varNewAtt = objNewRef.GetAttributes
              For intCnt = 0 To UBound(varOldAtt)
                varNewAtt(intCnt).TextString = varOldAtt(intCnt).TextString
                objNewRef.Update
                varNewAtt(intCnt).InsertionPoint = varOldAtt(intCnt).InsertionPoint
                If varNewAtt(intCnt).Alignment <> acAlignmentLeft And varNewAtt(intCnt).Alignment <> acAlignmentFit And varNewAtt(intCnt).Alignment <> acAlignmentAligned Then
                varNewAtt(intCnt).TextAlignmentPoint = varOldAtt(intCnt).TextAlignmentPoint
                End If

'               Debug.Print "NEWATT INSX= " & CStr(varNewAtt(intCnt).InsertionPoint(0))
'                Debug.Print "NEWATT INSY= " & varNewAtt(intCnt).InsertionPoint(1)
'                Debug.Print "OLDATT INSX= " & varOldAtt(intCnt).InsertionPoint(0)
'                Debug.Print "OLDATT INSY= " & varOldAtt(intCnt).InsertionPoint(1)
'                Debug.Print "***********************************"
               
                varNewAtt(intCnt).Rotation = varOldAtt(intCnt).Rotation
              Next intCnt
            End If
            objNewRef.Layer = objBlkRef.Layer
            objNewRef.Linetype = objBlkRef.Linetype
            objNewRef.LinetypeScale = objBlkRef.LinetypeScale
            objNewRef.Lineweight = objBlkRef.Lineweight
            If Left(ThisDrawing.GetVariable("acadver"), 2) = "16" Then
              objNewRef.TrueColor = objBlkRef.TrueColor
            Else
              objNewRef.color = objBlkRef.color
            End If
            objNewRef.Visible = objBlkRef.Visible
'            objNewRef.Update
'            If objNewRef.HasAttributes Then
'              varOldAtt = objBlkRef.GetAttributes
'              varNewAtt = objNewRef.GetAttributes
'              For intCnt = 0 To UBound(varOldAtt)
'                'varNewAtt(intCnt).TextString = varOldAtt(intCnt).TextString
'
'                varNewAtt(intCnt).InsertionPoint = varOldAtt(intCnt).InsertionPoint
''               Debug.Print "NEWATT INSX= " & CStr(varNewAtt(intCnt).InsertionPoint(0))
''                Debug.Print "NEWATT INSY= " & varNewAtt(intCnt).InsertionPoint(1)
''                Debug.Print "OLDATT INSX= " & varOldAtt(intCnt).InsertionPoint(0)
''                Debug.Print "OLDATT INSY= " & varOldAtt(intCnt).InsertionPoint(1)
''                Debug.Print "***********************************"
'
'                'varNewAtt(intCnt).Rotation = varOldAtt(intCnt).Rotation
'              Next intCnt
'            End If
            objBlkRef.Delete
            objNewRef.Update
          Else
            Set objNewRef = ThisDrawing.PaperSpace.InsertBlock(dblInsPt, objBlkRef.Name, dblScale(0), dblScale(1), dblScale(2), dblRotRad)
            If objNewRef.HasAttributes Then
              varOldAtt = objBlkRef.GetAttributes
              varNewAtt = objNewRef.GetAttributes
              For intCnt = 0 To UBound(varOldAtt)
                varNewAtt(intCnt).TextString = varOldAtt(intCnt).TextString
              Next intCnt
            End If
            objNewRef.Layer = objBlkRef.Layer
            objNewRef.Linetype = objBlkRef.Linetype
            objNewRef.LinetypeScale = objBlkRef.LinetypeScale
            objNewRef.Lineweight = objBlkRef.Lineweight
            If Left(ThisDrawing.GetVariable("acadver"), 2) = "16" Then
              objNewRef.TrueColor = objBlkRef.TrueColor
            Else
              objNewRef.color = objBlkRef.color
            End If
            objNewRef.Visible = objBlkRef.Visible
            objBlkRef.Delete
            objNewRef.Update
            End If

        End If
      End If
    Next objEnt
     
ExitHere:
Exit Sub

ErrorControl:
  Select Case Err.Number
  Case Else
      MsgBox "''" & Err.Description & "'' error has occured in UnMirror" & vbCr & _
      "All Blocks May NOT have updated correctly" & vbCrLf & _
      "Please report the error to Cad Manager", vbCritical, "Error in UnMirror"
      GoTo ExitHere
  End Select
 


End Sub

Function KillSet(strSet As String)
  Dim objSelSet As AcadSelectionSet
  Dim objSelSets As AcadSelectionSets
 
  Set objSelSets = ThisDrawing.SelectionSets
     
  For Each objSelSet In objSelSets
    If objSelSet.Name = strSet Then
      ThisDrawing.SelectionSets.Item(strSet).Delete
    Exit For
    End If
  Next

End Function


Maverick®

  • Seagull
  • Posts: 14778
Re: Block Unmirror
« Reply #5 on: December 21, 2006, 11:43:32 PM »
Hey Jeremie!  Good to see you.  Hope the new venture is going well and you have a great Christmas!

jjs

  • Guest
Re: Block Unmirror
« Reply #6 on: March 02, 2007, 01:20:56 AM »
Hey Maverick,
I did have a wonderful Christmas. Almost time for Easter now.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Block Unmirror
« Reply #7 on: March 02, 2007, 09:13:34 AM »
Hey jjs, good to see you around.  Dont be a stranger
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

jjs

  • Guest
Re: Block Unmirror
« Reply #8 on: March 02, 2007, 11:16:25 AM »
I have some ABS programming to do, so I will be around more often.

Arizona

  • Guest
Re: Block Unmirror
« Reply #9 on: March 02, 2007, 06:49:26 PM »
Hi Jeremie,

Where you been for so long?
Glad you are back :-)

P.S. I came across a picture of you the other day, do you want it?

jjs

  • Guest
Re: Block Unmirror
« Reply #10 on: March 04, 2007, 10:13:57 PM »
Me, are you sure it is not macgyver?