Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello. I'm trying to make an automatic zone designator on both sides of the polyline. The macro is to select an existing polyline, offset it to both sides, draw closing polyline segments, and then combine all 4 polyline segments into one object. I'm stuck, I can't assign an array with polylines to the Selection set and then to the group. And then by PEDIT to join it. Please help, I don't know why the error occurs...
Sub Example_Offset()
' This example offset polyline in bouth sides and close.
Dim ssetObj As AcadSelectionSet
Dim oPolyline As AcadLWPolyline
Dim oGrupa As AcadGroup
Dim Dlugosc As String
Dim Uchwyt As String
Dim tbWsp As Variant
Dim tbP(0 To 3) As Double
Dim Off As Double
Dim oBokGora As AcadLWPolyline
Dim oBokDol As AcadLWPolyline
Dim oBokPrawy As AcadLWPolyline
Dim oBokLewy As AcadLWPolyline
Dim oOff As Variant
Dim tbStrefa(0 To 3) As Variant
Dim sGrupaNazwa As String
Dim sName As String
AppActivate ThisDrawing.Application.Caption
' input offset distance data
Off = InputBox("Your offset distance", , "5")
' Create the selection set
sName = "SS1"
On Error Resume Next
Set ssetObj = ThisDrawing.SelectionSets.Add(sName)
If Err.Number <> 0 Then
Set ssetObj = ThisDrawing.SelectionSets.Item(sName)
AddSelectionSet.Clear
End If
On Error GoTo 0
' Add objects (polyline) to a selection set by prompting user to select on the screen
ssetObj.SelectOnScreen
Set oPolyline = ThisDrawing.SelectionSets(sName).Item(0)
Dlugosc = oPolyline.Length
Uchwyt = oPolyline.Handle
MsgBox "Length is: " & Dlugosc
MsgBox "Handle is: " & Uchwyt
oOff = oPolyline.Offset(Off * (-1))
' set first polyline to variable
Set oBokGora = oOff(0)
oBokGora.Layer = "0"
tbP(0) = oBokGora.Coordinates(0)
tbP(1) = oBokGora.Coordinates(1)
oOff = oPolyline.Offset(Off * 1)
' set second polyline to variable
Set oBokDol = oOff(0)
oBokDol.Layer = "0"
tbP(2) = oBokDol.Coordinates(0)
tbP(3) = oBokDol.Coordinates(1)
' set third polyline to variable
Set oBokLewy = ThisDrawing.ModelSpace.AddLightWeightPolyline(tbP)
oBokLewy.Layer = "0"
tbWsp = oBokGora.Coordinates
tbP(0) = oBokGora.Coordinates(UBound(tbWsp) - 1)
tbP(1) = oBokGora.Coordinates(UBound(tbWsp))
tbWsp = oBokDol.Coordinates
tbP(2) = oBokDol.Coordinates(UBound(tbWsp) - 1)
tbP(3) = oBokDol.Coordinates(UBound(tbWsp))
' set fourth polyline to variable
Set oBokPrawy = ThisDrawing.ModelSpace.AddLightWeightPolyline(tbP)
oBokPrawy.Layer = "0"
ThisDrawing.Regen (acAllViewports)
' set array of polylines
Set tbStrefa(0) = oBokGora
Set tbStrefa(1) = oBokDol
Set tbStrefa(2) = oBokPrawy
Set tbStrefa(3) = oBokLewy
ThisDrawing.SelectionSets(sName).Delete
sName = "SS2"
On Error Resume Next
Set ssetObj = ThisDrawing.SelectionSets.Add(sName)
If Err.Number <> 0 Then
Set ssetObj = ThisDrawing.SelectionSets.Item(sName)
AddSelectionSet.Clear
End If
On Error GoTo 0
' add items to selection set from array
ssetObj.AddItems tbStrefa
sName = "Group1"
Set oGrupa = ThisDrawing.Groups.Add(sName)
' add items to group from selection set
oGrupa.AppendItems ssetObj
sGrupaNazwa = oGrupa.Name
' in english acad version "M"-multiple, "J"-join, "G"-group
' run pedit command to join polylines
ThisDrawing.SendCommand "_PEDIT" & vbCr & "M" & vbCr & "G" & vbCr & sName & vbCr & vbCr & "J" & vbCr & "0.0" & vbCr & vbCr
' deleting group and selection set
oGrupa.Delete
ssetObj.Delete
ThisDrawing.Regen (acAllViewports)
End Sub
Solved! Go to Solution.