请大家指点指点啊!!急
有以下代码,根据不同情况实行拉伸实体的操作,可为什么存在拉伸路径的时候,只能够拉伸ExtrudeFace层中的面,而须绘制路径的时候则可以拉伸所有面!Private Sub CInput_Click()<BR> <BR> Form2.Hide<BR> Dim objlayer As AcadLayer<BR> <BR> Dim r As Integer<BR> Dim t As Integer<BR> <BR> r = Val(PHeight.Text)<BR> t = Val(RThickness.Text)<BR> 如果层ExtrudePath不存在,就创建一个明为ExtrudePath的层,如果存在就置为当前层。<BR>On Error Resume Next
If IsNull(ThisDrawing.Layers.Item("ExtrudePath")) Then<BR>Set objlayer = ThisDrawing.Layers.Add("ExtrudePath")<BR>ThisDrawing.ActiveLayer = objlayer
Else<BR>For Each objlayer In ThisDrawing.Layers<BR>If objlayer.Name = "ExtrudePath" Then<BR>ThisDrawing.ActiveLayer = objlayer<BR>Exit For<BR>End If<BR>Next<BR>End If
判断ExtrudePath层中是否存在三维多段线,如果有两条以上,就要求用户选择其中一条做为拉伸路径objline,如果只有一条,就直接作为拉伸路径objline,如果没有的话,就绘制一条拉伸路径objline
Dim objline As Acad3DPolyline<BR>Dim tpoint As Variant<BR>tpoint(0) = Val(Form2.XPoint.Text)<BR>tpoint(1) = Val(Form2.YPoint.Text)<BR>tpoint(2) = Val(Form2.ZPoint.Text)
<BR>Dim sset As AcadSelectionSet<BR>Dim sset1 As AcadSelectionSet
Dim y As Integer
<BR>y = ThisDrawing.SelectionSets.Count
While (y > 0)<BR>Set sset = ThisDrawing.SelectionSets.Item(y - 1)<BR>If sset.Name = "3dPLine" Or "A3dPLine" Then<BR>sset.Delete<BR>End If<BR>y = y - 1<BR>Wend
Set sset = ThisDrawing.SelectionSets.Add("3dPLine")<BR>Set sset1 = ThisDrawing.SelectionSets.Add("A3dPLine")
Dim gpcode(1) As Integer<BR>Dim datavalue(1) As Variant
gpcode(0) = 0<BR>datavalue(0) = "PolyLine"<BR>gpcode(1) = 8<BR>datavalue(1) = "ExtrudePath"
<BR>sset.Select acSelectionSetAll, , , gpcode, datavalue<BR>If sset.Count > 1 Then
MsgBox "满足条件的拉伸路径存在多条,请选择一条!"
sset1.SelectOnScreen gpcode, datavalue<BR>Set objline = sset1.Item(0)
objline.Move objline.Coordinate(0), tpoint
For i = 0 To sset.Count - 1
If Not sset.Item(i).ObjectID = sset1.Item(0).ObjectID Then<BR>sset.Item(i).Delete<BR>End If
Next i
Else
If sset.Count = 1 Then<BR>Set objline = sset.Item(0)<BR>objline.Move objline.Coordinate(0), tpoint
Else<BR>For Each objlayer In ThisDrawing.Layers<BR>If objlayer.Name = "ExtrudePath" Then<BR>ThisDrawing.ActiveLayer = objlayer<BR>End If<BR>Exit For<BR>Next
绘制三维多段线,且其起始点已经确定
On Error GoTo errhandle<BR>'Dim p1 As Variant<BR>Dim p2 As Variant<BR>'p1 = ThisDrawing.Utility.GetPoint(, vbCr & "请输入第一点:")<BR>p2 = ThisDrawing.Utility.GetPoint(, vbCr & "请输入下一点:")<BR>Dim pnt(5) As Double<BR>pnt(0) = Val(Form2.XPoint.Text): pnt(1) = Val(Form2.YPoint.Text): pnt(2) = Val(Form2.ZPoint.Text)<BR>pnt(3) = p2(0): pnt(4) = p2(1): pnt(5) = p2(2)
Set objline = ThisDrawing.ModelSpace.Add3DPoly(pnt)<BR>Do While True<BR>p2 = ThisDrawing.Utility.GetPoint(p2, vbCr & "请输入下一点:")<BR>objline.AppendVertex p2<BR>Loop<BR>errhandle:<BR>End If
End If
把该三维多段线的起始点做为新建ucs的原点,第二点作为另外一个参数<BR> <BR>Dim endpoint1(0 To 2) As Double<BR>Dim endpoint2(0 To 2) As Double
Dim coord1 As Variant<BR>Dim coord2 As Variant<BR> <BR>Dim str1 As String<BR>Dim str2 As String
'coord1 = objline.Coordinate(0)
'coord2 = objline.Coordinate(1)<BR>coord1 = ThisDrawing.Utility.TranslateCoordinates(objline.Coordinate(0), acWorld, acUCS, False)<BR>coord2 = ThisDrawing.Utility.TranslateCoordinates(objline.Coordinate(1), acWorld, acUCS, False)
<BR>endpoint1(0) = coord1(0): endpoint1(1) = coord1(1): endpoint1(2) = coord1(2)<BR>endpoint2(0) = coord2(0): endpoint2(1) = coord2(1): endpoint2(2) = coord2(2)
<BR>str1 = endpoint1(0) & "," & endpoint1(1) & "," & endpoint1(2)<BR>str2 = endpoint2(0) & "," & endpoint2(1) & "," & endpoint2(2)
ThisDrawing.SendCommand "_ucs " & "N" & vbCr & "za" & vbCr & str1 & vbCr & str2 & vbCr
分别在层extrudeFacel和0层中绘制面
以下的创建面的函数存在于模块中<BR>Call CreateRegion1(100 * Val(Form1.LPbox1.Text), 100 * Val(Form1.MCbox1.Text), 100 * Val(Form1.RPbox1.Text), 100 * Val(Form1.LTbox1.Text), 100 * ValForm1.RTbox1.Text))
建立包含所有ExtrudeFace层中的面的选择集ssetF<BR>Dim ssetF As AcadSelectionSet<BR>Dim x As Integer<BR>x = ThisDrawing.SelectionSets.Count<BR>While (x > 0)<BR>Set ssetF = ThisDrawing.SelectionSets.Item(x - 1)<BR>If ssetF.Name = "ExtrudeFace" Then<BR>ssetF.Delete<BR>End If<BR>x = x - 1<BR>Wend<BR>Set ssetF = ThisDrawing.SelectionSets.Add("ExtrudeFace")
<BR>gpcode(0) = 0<BR>datavalue(0) = "Region"<BR>gpcode(1) = 8<BR>datavalue(1) = "ExtrudeFace"<BR>ssetF.Select acSelectionSetAll, , , gpcode, datavalue
拉伸所有ExtrudeFace层中的面创建实体
Dim obj3dPath() As Acad3DSolid<BR>For i = 0 To ssetF.Count - 1<BR>ReDim obj3dPath(i)
<BR>Set obj3dPath(i) = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(ssetF(i), objline)<BR>obj3dPath(i).TrueColor = ssetF(i).TrueColor<BR>ssetF(i).Delete<BR>obj3dPath(i).Layer = "Path"<BR>Next i
objline.Layer = "0"
建立包含所有0层中的面的选择集sseth
Dim sseth As AcadSelectionSet<BR>i = ThisDrawing.SelectionSets.Count
While (i > 0)<BR>Set sseth = ThisDrawing.SelectionSets.Item(i - 1)<BR>If sseth.Name = "helpobj" Then<BR>sseth.Delete<BR>End If<BR>i = i - 1<BR>Wend
gpcode(0) = 0<BR>datavalue(0) = "Region"<BR>gpcode(1) = 8<BR>datavalue(1) = "0"<BR>sseth.Select acSelectionSetAll, , , gpcode, datavalue
拉伸0层中的面<BR>Dim hobj3dPath As Acad3DSolid
Set hobj3dPath = ThisDrawing.ModelSpace.AddExtrudedSolidAlongPath(sseth.Item(0), objline)<BR>objline.Delete<BR>sseth.Item(0).Delete<BR>hobj3dPath.Layer = "0"<BR>End If
end sub<BR>
页:
[1]