VB | VB Create Autocad Session | |
VBA | Add point on a drawing (Macro) | HATCH |
Select text boxes and extract text to a "txt" file | ||
Selection | ||
Extrude | ||
AddText |
Notes
Rotation - Counter clockwise=positive | ||||
VB Create Autocad Session | TOP | Add point on a drawing (Macro) | TOP |
$ =
"########0.0" Dim XT(2000), YT(2000) Dim PP(2) As Double On Error Resume Next ' GESTION DES ERREURS Set acadApp = GetObject(, "AutoCAD.Application") If ERR Then ERR.Clear Set acadApp = CreateObject("AutoCAD.Application") If ERR Then MsgBox ERR.Description Exit Sub End If End If acadApp.Visible = True ' AUTOCAD acadApp.Top = 0 acadApp.Left = 0 acadApp.WIDTH = 1024 acadApp.Height = 740 Set ObjAcad = GetObject(, "Autocad.Application") ObjAcad.Visible = True Set AcadDoc = acadApp.ActiveDocument Set AcadUtil = AcadDoc.Utility activeDoc.ActiveSpace = acModelSpace 'INITIALISATION DES POINTS |
Sub GEORGE() Open "C:\TEMP\RefSyn_Practice\EX4.TXT" For Input As 1 Dim PP(2) As Double I = 0 While EOF(1) = False I = I + 1 Input #1, A, B, C PP(0) = A PP(1) = B PP(2) = C Set tmpPT = ThisDrawing.ModelSpace.AddPoint(PP) Wend End Sub |
||
Plot a set of points (or draw a polyline or a line from VB) |
Create a series of non connected lines |
||
Dim P1() As
Double Dim P2() As Double '======================================= A$ = "########0.0" On Error Resume Next ' GESTION DES ERREURS Set acadApp = GetObject(, "AutoCAD.Application") If Err Then Err.Clear Set acadApp = CreateObject("AutoCAD.Application") If Err Then MsgBox Err.Description Exit Sub End If End If acadApp.Visible = True ' AUTOCAD acadApp.Top = 0 acadApp.Left = 0 acadApp.Width = 1024 acadApp.Height = 740 Set ObjAcad = GetObject(, "Autocad.Application") ObjAcad.Visible = True Set AcadDoc = acadApp.ActiveDocument Set AcadUtil = AcadDoc.Utility activeDoc.ActiveSpace = acModelSpace '======================================= ReDim P1(0 To 2 * NX + 1) ReDim P2(0 To 2 * NY + 1) '======================================= Set An = ObjAcad.ActiveDocument.ModelSpace.AddPoint(PP) ' add points (nodes) Set An = ObjAcad.ActiveDocument.ModelSpace.AddPoint(PP) ' add points (nodes) Set An = ObjAcad.ActiveDocument.ModelSpace.AddPoint(PP) ' add points (nodes)
|
Sub survey() Dim mylineobject As AcadLine Dim startpoint(0 To 2) As Double Dim endpoint(0 To 2) As Double 'FIRST LINE startpoint(0) = 0 startpoint(1) = 0 startpoint(2) = 0 endpoint(0) = 1 endpoint(1) = 0 endpoint(2) = 0 'SECOND LINE startpoint(0) = 0.5 startpoint(1) = -0.5 startpoint(2) = 0 endpoint(0) = 1 endpoint(1) = 0 endpoint(2) = 0
|
||
Select text boxes and extract text to a "txt" file | Various VBA Methods | ||
Sub SELECT_TEXT() ' Create a new selection set Dim sset As AcadSelectionSet Dim xdataType As Variant Dim xdata As Variant Dim xd As Variant Dim appName As String Dim table_text(10000) appName = "MY_APP" Set sset = ThisDrawing.SelectionSets.Add("TEXT_SETZ") ' Prompt the user to select objects ' and add them to the selection set. ' To finish selecting, press ENTER. FilterType = 0 FilterData = "TEXT" Dim OBJ_NAME(10000), TEXT_CONTENT(10000) As String Dim I_HANDLE(1000) As Variant i = 0 sset.SelectOnScreen ' Iterate through the selection set ' and color each object blue Dim entry As AcadEntity For Each entry In sset entry.color = acBlue i = i + 1 OBJ_NAME(i) = entry.ObjectName If OBJ_NAME(i) = "AcDbText" Then I_HANDLE(i) = entry.Handle End If If TypeOf entry Is IAcadText Then Debug.Print entry.TextString table_text(i) = entry.TextString End If entry.Update Next entry imax = i - 1 Open "c:\temp\points_4.txt" For Output As 1 For i = 1 To imax Print #1, table_text(i) Next i Close 1 End Sub |
Public Sub
CreateCircle() Dim CircleCenter(0 To 2) As Double Dim CircleObj As AcadCircle CircleCenter(0) = 1.2: CircleCenter(1) = 22: CircleCenter(2) = 0 Set CircleObj = ThisDrawing.ModelSpace.AddCircle(CircleCenter, 15) CircleObj.Color = acGreen End Sub Public Sub OpenFile() Dim FileName As String FileName = InputBox("Text") If
Dir(FileName) <> "" Then Public Sub
TestIfSaved()
|
||
Add3DFace |
||
'
Excel VBA code to run in a worksheet object. |
Open "C:\TEMP\points.TXT" For Input As 1 |
|
Sub Example_Add() ' This example adds a block, dictionary, dimension style, ' group, layer, registered application, selection set, ' textstyle, view, viewport and UCS using the Add method. GoSub ADDBLOCK GoSub ADDDICTIONARY GoSub ADDDIMSTYLE GoSub ADDGROUP GoSub ADDLAYER GoSub ADDREGISTEREDAPP GoSub ADDSELECTIONSET GoSub ADDTEXTSTYLE GoSub ADDVIEW GoSub ADDVIEWPORT GoSub ADDUCS Exit Sub ADDBLOCK:
' Create a new block called "New_Block"
Dim blockObj As AcadBlock
' Define the block Dim insertionPnt(0 To 2) As Double insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0# ' Add the block to the blocks collection Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, "New_Block") MsgBox blockObj.name & " has been added." & vbCrLf & _ "Origin: " & blockObj.origin(0) & ", " & blockObj.origin(1) _ & ", " & blockObj.origin(2), , "Add Example" Return ADDDICTIONARY:
' Create a new dictionary called "New_Dictionary"
Dim dictObj As AcadDictionary
' Add the dictionary to the dictionaries collection Set dictObj = ThisDrawing.Dictionaries.Add("New_Dictionary") MsgBox dictObj.name & " has been added.", , "Add Example" Return ADDDIMSTYLE:
' Create a new dimension style called "New_Dimstyle" in current drawing
Dim DimStyleObj As AcadDimStyle
' Add the dimstyle to the dimstyles collection Set DimStyleObj = ThisDrawing.DimStyles.Add("New_Dimstyle") MsgBox DimStyleObj.name & " has been added.", , "Add Example" Return ADDGROUP:
' Create a new group called "New_Group" in current drawing
Dim groupObj As AcadGroup
' Add the group to the groups collection Set groupObj = ThisDrawing.Groups.Add("New_Group") MsgBox groupObj.name & " has been added.", , "Add Example" Return ADDLAYER:
' This example creates a new layer called "New_Layer"
Dim layerObj As AcadLayer
' Add the layer to the layers collection Set layerObj = ThisDrawing.Layers.Add("New_Layer") ' Make the new layer the active layer for the drawing ThisDrawing.ActiveLayer = layerObj ' Display the status of the new layer MsgBox layerObj.name & " has been added." & vbCrLf & _ "LayerOn Status: " & layerObj.LayerOn & vbCrLf & _ "Freeze Status: " & layerObj.Freeze & vbCrLf & _ "Lock Status: " & layerObj.Lock & vbCrLf & _ "Color: " & layerObj.Color, , "Add Example" Return ADDREGISTEREDAPP:
' Create a registered application named "New_RegApp" in current drawing
Dim RegAppObj As AcadRegisteredApplication
' Add the registered application to the registered applications collection Set RegAppObj = ThisDrawing.RegisteredApplications.Add("New_RegApp") MsgBox RegAppObj.name & " has been added.", , "Add Example" Return ADDSELECTIONSET:
' Create a selectionset named "New_SelectionSet" in current drawing
Dim ssetObj As AcadSelectionSet
' Add the selection set to the selection sets collection Set ssetObj = ThisDrawing.SelectionSets.Add("New_SelectionSet") MsgBox ssetObj.name & " has been added." & vbCrLf & _ "The number of items in the selection set is " & ssetObj.count _ , , "Add Example" Return ADDTEXTSTYLE:
' Create a textstyle named "New_Textstyle" in current drawing
Dim txtStyleObj As AcadTextStyle
' Add the textstyle to the textstyles collection Set txtStyleObj = ThisDrawing.TextStyles.Add("New_Textstyle") MsgBox txtStyleObj.name & " has been added." & vbCrLf & _ "Height: " & txtStyleObj.height & vbCrLf & _ "Width: " & txtStyleObj.width, , "Add Example" Return ADDVIEW:
' Create a view named "New_View" in current drawing
Dim viewObj As AcadView
' Add the view to the views collection Set viewObj = ThisDrawing.Views.Add("New_View") MsgBox viewObj.name & " has been added." & vbCrLf & _ "Height: " & viewObj.height & vbCrLf & _ "Width: " & viewObj.width, , "Add Example" Return ADDVIEWPORT:
' Create a viewport named "New_Viewport" in current drawing
Dim vportObj As AcadViewport
' Add the viewport to the viewports collection Set vportObj = ThisDrawing.Viewports.Add("New_Viewport") MsgBox vportObj.name & " has been added." & vbCrLf & _ "GridOn Status: " & vportObj.GridOn & vbCrLf & _ "OrthoOn Status: " & vportObj.OrthoOn & vbCrLf & _ "SnapOn Status: " & vportObj.SnapOn, , "Add Example" Return ADDUCS:
' Create a UCS named "New_UCS" in current drawing
Dim ucsObj As AcadUCS
Dim origin(0 To 2) As Double
Dim xAxisPnt(0 To 2) As Double
Dim yAxisPnt(0 To 2) As Double
' Define the UCS origin(0) = 4#: origin(1) = 5#: origin(2) = 3# xAxisPnt(0) = 5#: xAxisPnt(1) = 5#: xAxisPnt(2) = 3# yAxisPnt(0) = 4#: yAxisPnt(1) = 6#: yAxisPnt(2) = 3# ' Add the UCS to the UserCoordinatesSystems collection Set ucsObj = ThisDrawing.UserCoordinateSystems.Add(origin, xAxisPnt, yAxisPnt, "New_UCS") MsgBox ucsObj.name & " has been added." & vbCrLf & _ "Origin: " & ucsObj.origin(0) & ", " & ucsObj.origin(1) _ & ", " & ucsObj.origin(2), , "Add Example" Return End Sub
|
Sub Example_ZoomAll() |
|
|
|
|
Sub Example_AddFitPoint() |
Sub Example_AddPoint() |
|
|
|
|
Sub Example_AddExtrudedSolid() |
Sub Example_Add3DFace() |
|
TOP | ||
Public Sub SelectionSetInfo() |
Sub Example_AddExtrudedSolid() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|