2008-09-19

Rabbit out of the hat.

A few weeks ago, we made the rabbit disappear, this week we will make it reappear (making the invisible visible again). The tricky part with invisible things is how do you get a hold of them in the first place. Well, you have to "grab them" by one of their properties and then "feed this" to other sub.

Private Sub Set_InvisibleObjSS(ByRef acSS1 As AcadSelectionSet)
'------------------------------------------------------------------------------
'
'
'------------------------------------------------------------------------------
Dim acSS As AcadSelectionSet
Dim dPt1(0 To 2) As Double
Dim dPt2(0 To 2) As Double
Dim iCode(0) As Integer
Dim vVal(0) As Variant
'''''''''''''''''''''''''''''''''''''''
iCode(0) = 60 'visibilty pair
vVal(0) = 1 '1=invisible, 0=visible
Set acSS = ClearSS("INVIS")

acSS.Select acSelectionSetAll, dPt1, dPt2, iCode, vVal 'ALL OBJECTS
Set acSS1 = acSS

End Sub

Public Function Set_SsInvisibilityOn(ByRef acSS As AcadSelectionSet)
'------------------------------------------------------------------------------
'
'
'------------------------------------------------------------------------------
Dim acSS As AcadSelectionSet
Dim acObj As AcadObject
Dim acLyr As AcadLayer
Dim acLyrs As AcadLayers
Dim sCurrLyr As String
'''''''''''''''''''''''''''''''''''''''

Set acLyrs = ThisDrawing.Layers
'------------------------------------------------------------------------------
'Cycle through all objects
'------------------------------------------------------------------------------
For Each acObj In acSS
If acObj.Visible = False Then
sCurrLyr = acObj.layer
Set acLyr = acLyrs.Item(sCurrLyr)
'Check for locked layer, and unlock it if it is
If acLyr.Lock Then
acLyr.Lock = False 'Unlock the Layer.
acObj.Visible = True 'Display the invisible item
acLyr.Lock = True 'Re-lock the Layer.
Else
acObj.Visible = True
End If
End If
acObj.Update
Next acObj

End Function

2008-09-12

The king's clothes are missing.

Have you ever wanted to take off the "clothes" of Mtext. Well, here you are. A Mtext unformatter. It is a nice little routine, that I built from a post on the Autodesk forum site. I apologize to the author but I do not have their name. I tweaked it just a little but the main idea is still there.

Public Function MText_Unformat(ByVal sTxt As String) As String
'------------------------------------------------------------------------------
'Remove formatting strings
'
'Value Examples:
' \A Sets the alignment value; valid values: 0, 1, 2 (bottom, center, top)
' \Cvalue; Changes to the specified color
' \Hvalue; Changes to the specified text height
' \Hvaluex; Changes to multiple of mtext object's property
' \L...\l Turns underline on and off
' \O...\o Turns overline on and off
' \P Ends paragraph/Carriage return
' \Qangle; Changes obliquing angle
' \S...^...; Stacks the subsequent text at the \ or ^ symbol
' \Tvalue; Adjusts the space between characters
' \Wvalue; Changes width factor to produce wide text
' \~ Inserts a nonbreaking space
' \\ Inserts a backslash
' \{...\} Inserts an opening and closing brace
' \File name; Changes to the specified font file
'
'------------------------------------------------------------------------------
Dim P1 As Integer
Dim P2 As Integer
Dim P3 As Integer
Dim iStart As Integer
Dim sComp As String
Dim sReplace As String
Dim sLittle As String
'''''''''''''''''''''''''''''''''''''''
Debug.Print sTxt
'------------------------------------------------------------------------------
'Remove alignment codes
'------------------------------------------------------------------------------
Select Case Left(sTxt, 4)
Case "\A0;", "\A1;", "\A2;"
sTxt = Mid(sTxt, P1 + 5)
End Select
iStart = 1
'------------------------------------------------------------------------------
'Replace octal code values with strings
'------------------------------------------------------------------------------
Do
P1 = InStr(sTxt, "%%")
If P1 = 0 Then
Exit Do
Else
Select Case Mid(sTxt, P1 + 2, 1)
Case "P"
sTxt = Replace(sTxt, "%%P", "+or-")
Case "D"
sTxt = Replace(sTxt, "%%D", " deg")
End Select
End If
Loop

Do
P1 = InStr(iStart, sTxt, "\", vbTextCompare)
If P1 = 0 Then Exit Do
sComp = Mid(sTxt, P1, 2)
Select Case sComp
Case "\p"
P2 = InStr(1, sTxt, ";")
sTxt = Mid(sTxt, P2 + 1)
Case "\A", "\C", "\f", "\F", "\H", "\Q", "\T", "\W"
P2 = InStr(P1 + 2, sTxt, ";", vbTextCompare)
P3 = InStr(P1 + 2, sTxt, sComp, vbTextCompare)
If P3 = 0 Then
sTxt = Left(sTxt, P1 - 1) & Mid(sTxt, P2 + 1)
End If
Do While P3 > 0
P2 = InStr(P3, sTxt, ";", vbTextCompare)
sTxt = Left(sTxt, P3 - 1) & Mid(sTxt, P2 + 1)
'Debug.Print sTxt, sComp
P3 = InStr(1, sTxt, sComp, vbTextCompare)
Loop
'sTxt = Left(sTxt, P3 - 1) & mid(sTxt, P3 + 1)
Case "\L", "\O"
sLittle = LCase(sComp)
P2 = InStr(P1 + 2, sTxt, sLittle, vbTextCompare)
If P2 = 0 Then
sTxt = Left(sTxt, P1 - 1) & Mid(sTxt, P1 + 2)
Else
sTxt = Left(sTxt, P1 - 1) & Mid(sTxt, P1 + 2, P2 - (P1 + 2)) & Mid(sTxt, P2 + 2)
End If
Case "\S"
P2 = InStr(P1 + 2, sTxt, ";", vbTextCompare)
P3 = InStr(P1 + 2, sTxt, "/", vbTextCompare)
If P3 = 0 Or P3 > P2 Then
P3 = InStr(P1 + 2, sTxt, "#", vbTextCompare)
End If
If P3 = 0 Or P3 > P2 Then
P3 = InStr(P1 + 2, sTxt, "^", vbTextCompare)
End If
sTxt = Left(sTxt, P1 - 1) & Mid(sTxt, P1 + 2, P3 - (P1 + 2)) _
& "/" & Mid(sTxt, P3 + 1, (P2) - (P3 + 1)) & Mid(sTxt, P2 + 1)

Case "\U" 'Replace symbols with text
sLittle = Mid(sTxt, P1 + 3, 4)
Debug.Print sLittle
Select Case sLittle
Case "2248"
sReplace = "ALMOST EQUAL"
Case "2220"
sReplace = "ANGLE"
Case "2104"
sReplace = "CENTER LINE"
Case "0394"
sReplace = "DELTA"
Case "0278"
sReplace = "ELECTRIC PHASE"
Case "E101"
sReplace = "FLOW LINE"
Case "2261"
sReplace = "IDENTITY"
Case "E200"
sReplace = "INITIAL LENGTH"
Case "E102"
sReplace = "MONUMENT LINE"
Case "2260"
sReplace = "NOT EQUAL"
Case "2126"
sReplace = "OHM"
Case "03A9"
sReplace = "OMEGA"
Case "214A"
sReplace = "PROPERTY LINE"
Case "2082"
sReplace = "SUBSCRIPT2"
Case "00B2"
sReplace = "SQUARED"
Case "00B3"
sReplace = "CUBED"
End Select
sTxt = Replace(sTxt, "\U+" & sLittle, sReplace)
Case "\~"
sTxt = Replace(sTxt, "\~", " ")
Case "\\"
iStart = P1 + 2
sTxt = Replace(sTxt, "\\", "\")
GoTo Selectagain
Case "\P"
iStart = P1 + 1
GoTo Selectagain
Case Else
Exit Do
End Select
Selectagain:
Loop
'------------------------------------------------------------------------------
'Replace \P with vbCrLf
'------------------------------------------------------------------------------
Do
P1 = InStr(1, sTxt, "\P", vbTextCompare)
If P1 = 0 Then
Exit Do
Else
sTxt = Left(sTxt, P1 - 1) & vbCrLf & Mid(sTxt, P1 + 2)
End If
Loop
For iStart = 0 To 1
If iStart = 0 Then
sComp = "}"
Else
sComp = "{"
End If
P2 = InStr(1, sTxt, sComp)

Do While P2 > 0
sTxt = Left(sTxt, P2 - 1) & Mid(sTxt, P2 + 1)
P2 = InStr(1, sTxt, sComp)
Loop
Next iStart

MText_Unformat = sTxt

End Function

2008-09-05

The one constant is change..

Here are some constants I created that I use quite often. I made them global so they would be available to any routine I might write (just place them in a module that you can remember). You can create your own constants also or change these to your liking (you know what they say about constants..)


Global Const radian_30 = 0.52359877
Global Const radian_45 = 0.78539816
Global Const radian_60 = 1.04719755
Global Const radian_90 = 1.57079632
Global Const radian_120 = 2.0943951
Global Const radian_135 = 2.35619449
Global Const radian_150 = 2.61799387
Global Const radian_180 = 3.141592654
Global Const radian_210 = 3.665191429
Global Const PI = 3.14159265358979