- 积分
- 1125
- 明经币
- 个
- 注册时间
- 2014-11-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 Sring65 于 2025-5-27 17:47 编辑
可以试试WBlock导出文件后在块里面再插入为块
 - Sub Example_WBlock()
- ' This example creates several objects in model space and
- ' adds them to a selection set. This selection set is then
- ' output as a new drawing file.
-
- ' Create a Ray object in model space
- Dim rayObj As AcadRay
- Dim basePoint(0 To 2) As Double
- Dim SecondPoint(0 To 2) As Double
- basePoint(0) = 3#: basePoint(1) = 3#: basePoint(2) = 0#
- SecondPoint(0) = 1#: SecondPoint(1) = 3#: SecondPoint(2) = 0#
- Set rayObj = ThisDrawing.ModelSpace.AddRay(basePoint, SecondPoint)
-
- ' Create a polyline object in model space
- Dim plineObj As AcadLWPolyline
- Dim points(0 To 5) As Double
- points(0) = 3: points(1) = 7
- points(2) = 9: points(3) = 2
- points(4) = 3: points(5) = 5
- Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
- plineObj.Closed = True
- ' Create a line object in model space
- Dim lineObj As AcadLine
- Dim startPoint(0 To 2) As Double
- Dim endPoint(0 To 2) As Double
- startPoint(0) = 0: startPoint(1) = 0: startPoint(2) = 0
- endPoint(0) = 2: endPoint(1) = 2: endPoint(2) = 0
- Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)
-
- ' Create a circle object in model space
- Dim circObj As AcadCircle
- Dim centerPt(0 To 2) As Double
- Dim radius As Double
- centerPt(0) = 20: centerPt(1) = 30: centerPt(2) = 0
- radius = 3
- Set circObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)
- ' Create an ellipse object in model space
- Dim ellObj As AcadEllipse
- Dim majAxis(0 To 2) As Double
- Dim center(0 To 2) As Double
- Dim radRatio As Double
- center(0) = 5#: center(1) = 5#: center(2) = 0#
- majAxis(0) = 10: majAxis(1) = 20#: majAxis(2) = 0#
- radRatio = 0.3
- Set ellObj = ThisDrawing.ModelSpace.AddEllipse(center, majAxis, radRatio)
- ZoomAll
-
- ' Create a selection set
- Dim ssetObj As AcadSelectionSet
- Set ssetObj = ThisDrawing.SelectionSets.Add("WBLOCKSET")
-
- ' Iterate through the model space collection and add
- ' each item found to an array of objects
- ReDim objsInModelSpace(0 To ThisDrawing.ModelSpace.count - 1) As AcadEntity
- Dim I As Integer
- For I = 0 To ThisDrawing.ModelSpace.count - 1
- Set objsInModelSpace(I) = ThisDrawing.ModelSpace.Item(I)
- Next
-
- ' Add the array of objects into the selection set
- ssetObj.AddItems objsInModelSpace
-
- ' Output the selection set to a new file
- ThisDrawing.Wblock "C:\AutoCAD\WBlock_example.dwg", ssetObj
-
- End Sub
 - Sub Example_AttachExternalReference()
- ' This example displays all the blocks in the current drawing
- ' before and after adding an external reference.
- '
- ' This example uses the "city map.dwg" found in the Sample
- ' directory. If you do not have this drawing, or if it is
- ' in a different directory, insert a valid path and file name
- ' for the PathName variable below.
-
- Dim InsertPoint(0 To 2) As Double
- Dim insertedBlock As AcadExternalReference
- Dim tempBlock As AcadBlock
- Dim msg As String, PathName As String
-
- ' Define external reference to be inserted
- InsertPoint(0) = 1: InsertPoint(1) = 1: InsertPoint(2) = 0
- PathName = "c:\program files\autocad\sample\city map.dwg"
-
- ' Display current Block information for this drawing
- GoSub ListBlocks
-
- ' Add the external reference to the drawing
- Set insertedBlock = ThisDrawing.ModelSpace.AttachExternalReference(PathName, "XREF_IMAGE", InsertPoint, 1, 1, 1, 0, False)
-
- ThisDrawing.Application.ZoomAll
-
- ' Display new Block information for this drawing
- GoSub ListBlocks
-
- Exit Sub
- ListBlocks:
- msg = vbCrLf ' Reset message
-
- For Each tempBlock In ThisDrawing.Blocks
- msg = msg & tempBlock.name & vbCrLf ' Add Block to list
- Next
-
- MsgBox "The current blocks in this drawing are: " & msg
-
- Return
- End Sub
 - Sub Example_Bind()
- On Error GoTo ERRORHANDLER
-
- ' Define external reference to be inserted
- Dim xrefHome As AcadBlock
- Dim xrefInserted As AcadExternalReference
- Dim insertionPnt(0 To 2) As Double
- Dim PathName As String
- insertionPnt(0) = 1
- insertionPnt(1) = 1
- insertionPnt(2) = 0
- PathName = "c:/AutoCAD/sample/City map.dwg"
-
- ' Add the external reference
- Set xrefInserted = ThisDrawing.ModelSpace. _
- AttachExternalReference(PathName, "XREF_IMAGE", _
- insertionPnt, 1, 1, 1, 0, False)
- ZoomAll
- MsgBox "The external reference is attached."
-
- ' Bind the external reference definition
- ThisDrawing.Blocks.Item(xrefInserted.name).Bind False
- MsgBox "The external reference is bound."
- Exit Sub
- ERRORHANDLER:
- MsgBox Err.Description
- End Sub
|
|