Hello,
yes, it does more.
Here the Code:
The UserForm:
Sub De_Eng_Click()
ThisDrawing.stamp_lang = "T-SCHWPKT-D"
Unload UserForm1
End Sub
Sub De_Ru_Click()
ThisDrawing.stamp_lang = "T-SCHWPKT-R"
Unload UserForm1
End Sub
Sub De_Sp_Click()
ThisDrawing.stamp_lang = "T-SCHWPKT-S"
Unload UserForm1
End Sub
Sub En_Ru_Click()
ThisDrawing.stamp_lang = "T-SCHWPKT-RE"
Unload UserForm1
End Sub
Sub En_Sp_Click()
ThisDrawing.stamp_lang = "T-SCHWPKT-SE"
UserForm1.Hide
End Sub
and the Script:
Public objSSEnt As AcadSelectionSet
Public SelCount As Integer
Public objEnt As AcadPoint
Public get_point As Variant
Public stamp_lang As String
Sub select_point()
Dim SelCode(3) As Integer
Dim SelData(3) As Variant
Dim Filter1, Filter2 As Variant
On Error Resume Next
Set objSSEnt = ThisDrawing.SelectionSets.Add("SScollectPoint")
If Err.Number <> 0 Then
Set objSSEnt = ThisDrawing.SelectionSets.Item("SScollectPoint")
End If
objSSEnt.Clear
SelCode(0) = 410
SelData(0) = "Model"
SelCode(1) = -4
SelData(1) = "<OR"
SelCode(2) = 0
SelData(2) = "Point"
SelCode(3) = -4
SelData(3) = "OR>"
Filter1 = SelCode
Filter2 = SelData
objSSEnt.Select acSelectionSetAll, , , Filter1, Filter2
End Sub
Sub kill_points()
Call select_point
For Each objEnt In objSSEnt
objEnt.Delete
Next
End Sub
Sub set_cog()
ThisDrawing.SendCommand "_astm4balancepoint" & vbCr
End Sub
Sub read_point()
Dim location(0 To 2) As Double
Call select_point
For Each objEnt In objSSEnt
get_point = objEnt.Coordinates
location(0) = get_point(0): location(1) = get_point(1): location(2) = get_point(2)
Next
End Sub
Sub InsertBlock()
Dim ActiveDwg As AcadDocument
Dim TargetDwg As AcadDocument
Dim ActiveDwg_Name As String
Dim ActiveDwg_Path As String
Dim TargetDwg_Name As String
Dim TargetDwg_Path As String
'creating paths and names
ActiveDwg_Name = ThisDrawing.Name
ActiveDwg_Path = ThisDrawing.Path
TargetDwg_Name = Left(ActiveDwg_Name, 9) & "sheet01.dwg"
TargetDwg_Path = ActiveDwg_Path & "\" & Left(ActiveDwg_Name, Len(ActiveDwg_Name) - 4) & "\Details\"
Set ActiveDwg = Application.ActiveDocument
'check if file exists
If FileExists(TargetDwg_Path & TargetDwg_Name) Then
'create the specific block
Set TargetDwg = Application.Documents.Open(TargetDwg_Path & TargetDwg_Name)
Call Create_Block_w_Attribute
'update the block in target
Call mod_Block
'close the drawing
TargetDwg.Close (True) 'save & close
ActiveDwg.Activate
Else
MsgBox "There's no Drawing with the Name " & TargetDwg_Name & "!"
End If
End Sub
Sub mod_Block()
Dim grpCode(1) As Integer
Dim dataVal(1) As Variant
Dim ssetObj As AcadSelectionSet
Dim vAtt As Variant
Dim oBlockRef As AcadBlockReference
grpCode(0) = 0: dataVal(0) = "INSERT"
grpCode(1) = 2: dataVal(1) = stamp_lang
Set ssetObj = ActiveDocument.SelectionSets.Add("SS01")
ssetObj.Select acSelectionSetAll, , , grpCode, dataVal
For Each oBlockRef In ssetObj
If oBlockRef.HasAttributes Then
vAtt = oBlockRef.GetAttributes()
get_point(0) = Math.Round(get_point(0), 2)
get_point(1) = Math.Round(get_point(1), 2)
get_point(2) = Math.Round(get_point(2), 2)
vAtt(0).TextString = get_point(0)
vAtt(1).TextString = get_point(1)
vAtt(2).TextString = get_point(2)
End If
Next oBlockRef
ssetObj.Delete
End Sub
Sub Create_Block_w_Attribute()
'Check if Block already exists
On Error Resume Next
If ThisDrawing.Blocks(stamp_lang).Name = "" Then
' Define the block
Dim blockObj As AcadBlock
Dim insertionPnt(0 To 2) As Double
insertionPnt(0) = 0
insertionPnt(1) = 0
insertionPnt(2) = 0
Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, stamp_lang)
' Create the borders
Dim lineObj As AcadLine
Dim start_Line(0 To 2) As Double
Dim end_Line(0 To 2) As Double
Dim i As Integer
start_Line(0) = 0: start_Line(1) = 12: start_Line(2) = 0
end_Line(0) = 47: end_Line(1) = 12: end_Line(2) = 0
Set lineObj = blockObj.AddLine(start_Line, end_Line)
For i = 1 To 3
start_Line(0) = 0: start_Line(1) = start_Line(1) + 7.5: start_Line(2) = 0
end_Line(0) = 47: end_Line(1) = end_Line(1) + 7.5: end_Line(2) = 0
Set lineObj = blockObj.AddLine(start_Line, end_Line)
Next
start_Line(0) = 0: start_Line(1) = 47.5: start_Line(2) = 0
end_Line(0) = 47: end_Line(1) = 47.5: end_Line(2) = 0
Set lineObj = blockObj.AddLine(start_Line, end_Line)
start_Line(0) = 0: start_Line(1) = 0: start_Line(2) = 0
end_Line(0) = 47: end_Line(1) = 0: end_Line(2) = 0
Set lineObj = blockObj.AddLine(start_Line, end_Line)
start_Line(0) = 0: start_Line(1) = 0: start_Line(2) = 0
end_Line(0) = 0: end_Line(1) = 47.5: end_Line(2) = 0
Set lineObj = blockObj.AddLine(start_Line, end_Line)
start_Line(0) = 47: start_Line(1) = 0: start_Line(2) = 0
end_Line(0) = 47: end_Line(1) = 47.5: end_Line(2) = 0
Set lineObj = blockObj.AddLine(start_Line, end_Line)
start_Line(0) = 29: start_Line(1) = 0: start_Line(2) = 0
end_Line(0) = 29: end_Line(1) = 34.5: end_Line(2) = 0
Set lineObj = blockObj.AddLine(start_Line, end_Line)
' Create the Text
Dim MTextObj As AcadMText
Dim corner_hl(0 To 2) As Double
Dim corner_x(0 To 2) As Double
Dim corner_y(0 To 2) As Double
Dim corner_z(0 To 2) As Double
Dim corner_f(0 To 2) As Double
Dim width_hl, with_xyz As Double
Dim headline, footer, X_Line, Y_Line, Z_Line As String
corner_hl(0) = 0: corner_hl(1) = 45.7: corner_hl(2) = 0#
corner_x(0) = 0: corner_x(1) = 32.9: corner_x(2) = 0#
corner_y(0) = 0: corner_y(1) = 25.4: corner_y(2) = 0#
corner_z(0) = 0: corner_z(1) = 17.9: corner_z(2) = 0#
corner_f(0) = 0: corner_f(1) = 11.6: corner_f(2) = 0#
width_hl = 47
width_xyz = 29
X_Line = "X[m]"
Y_Line = "Y[m]"
Z_Line = "Z[m]"
MsgBox stamp_lang
If stamp_lang = "T-SCHWPKT-RE" Then
headline = ChrW(1062) & ChrW(1045) & ChrW(1053) & ChrW(1058) & ChrW(1056) & " " & ChrW(1058) & ChrW(1071) & ChrW(1046) & ChrW(1045) & ChrW(1057) & ChrW(1058) & ChrW(1048) & vbNewLine & "CENTER OF GRAVITY"
footer = ChrW(1042) & ChrW(1045) & ChrW(1057) & " [kg]" & vbNewLine & "WEIGHT [kg]"
ElseIf stamp_lang = "T-SCHWPKT-SE" Then
headline = "CENTER OF GRAVITY" & vbNewLine & "CENTRO DE GRAVEDAD"
footer = "WEIGHT [kg]" & vbNewLine & "PESO [kg]"
ElseIf stamp_lang = "T-SCHWPKT-D" Then
headline = "SCHWERPUNKT" & vbNewLine & "CENTER OF GRAVITY"
footer = "GEWICHT [kg]" & vbNewLine & "WEIGHT [kg]"
ElseIf stamp_lang = "T-SCHWPKT-R" Then
headline = "SCHWERPUNKT" & vbNewLine & ChrW(1062) & ChrW(1045) & ChrW(1053) & ChrW(1058) & ChrW(1056) & " " & ChrW(1058) & ChrW(1071) & ChrW(1046) & ChrW(1045) & ChrW(1057) & ChrW(1058) & ChrW(1048)
footer = "GEWICHT [kg]" & vbNewLine & ChrW(1042) & ChrW(1045) & ChrW(1057) & " [kg]"
ElseIf stamp_lang = "T-SCHWPKT-S" Then
headline = "SCHWERPUNKT" & vbNewLine & "CENTRO DE GRAVIDAD"
footer = "GEWICHT [kg]" & vbNewLine & "PESO [kg]"
End If
Set MTextObj = blockObj.AddMText(corner_hl, width_hl, headline)
MTextObj.height = 3.5
MTextObj.AttachmentPoint = acAttachmentPointMiddleCenter
Set MTextObj = blockObj.AddMText(corner_x, width_xyz, X_Line)
MTextObj.height = 3.5
MTextObj.AttachmentPoint = acAttachmentPointMiddleCenter
Set MTextObj = blockObj.AddMText(corner_y, width_xyz, Y_Line)
MTextObj.height = 3.5
MTextObj.AttachmentPoint = acAttachmentPointMiddleCenter
Set MTextObj = blockObj.AddMText(corner_z, width_xyz, Z_Line)
MTextObj.height = 3.5
MTextObj.AttachmentPoint = acAttachmentPointMiddleCenter
Set MTextObj = blockObj.AddMText(corner_f, width_xyz, footer)
MTextObj.height = 3.5
MTextObj.AttachmentPoint = acAttachmentPointMiddleCenter
' Add attributes to the block
Dim attributeObj As AcadAttribute
Dim height As Double
Dim mode As Long
Dim prompt1 As String
Dim prompt2 As String
Dim prompt3 As String
Dim prompt4 As String
Dim insertionPoint1(0 To 2) As Double
Dim insertionPoint2(0 To 2) As Double
Dim insertionPoint3(0 To 2) As Double
Dim insertionPoint4(0 To 2) As Double
Dim tag1 As String
Dim tag2 As String
Dim tag3 As String
Dim tag4 As String
Dim value As String
height = 3.5
mode = acAttributeModeVerify
prompt1 = "X"
prompt2 = "Y"
prompt3 = "Z"
prompt4 = "Weight"
insertionPoint1(0) = 30.5: insertionPoint1(1) = 29: insertionPoint1(2) = 0
insertionPoint2(0) = 30.5: insertionPoint2(1) = 21.5: insertionPoint2(2) = 0
insertionPoint3(0) = 30.5: insertionPoint3(1) = 14: insertionPoint3(2) = 0
insertionPoint4(0) = 30.5: insertionPoint4(1) = 4: insertionPoint4(2) = 0
tag1 = "T-X"
tag2 = "T-Y"
tag3 = "T-Z"
tag4 = "T-Weight"
value = "0.000"
Set attributeObj = blockObj.AddAttribute(height, mode, prompt1, insertionPoint1, tag1, value)
Set attributeObj = blockObj.AddAttribute(height, mode, prompt2, insertionPoint2, tag2, value)
Set attributeObj = blockObj.AddAttribute(height, mode, prompt3, insertionPoint3, tag3, value)
Set attributeObj = blockObj.AddAttribute(height, mode, prompt4, insertionPoint4, tag4, value)
' Insert the block, creating a block reference and an attribute reference
Dim blockRefObj As AcadBlockReference
insertionPnt(0) = 25
insertionPnt(1) = 15
insertionPnt(2) = 0
Set blockRefObj = ThisDrawing.PaperSpace.InsertBlock(insertionPnt, stamp_lang, 1#, 1#, 1#, 0)
Else
MsgBox "Block already exists and will be updated only!"
End If
End Sub
Function FileExists(FilePath As String) As Boolean
Dim TestStr As String
TestStr = ""
On Error Resume Next
TestStr = Dir(FilePath)
On Error GoTo 0
If TestStr = "" Then
FileExists = False
Else
FileExists = True
End If
End Function
Sub cog_to_dwg()
UserForm1.show 'Variable: stamp_lang
Call kill_points
Call set_cog
Call read_point
Call InsertBlock
Call kill_points
End Sub