Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proper syntax for Macros - AutoCAD 2000i 1

Status
Not open for further replies.

danreese

Technical User
Jun 20, 2001
3
US
I need to know the proper syntax for a macro that will insert a block (lets call it "Plug.dwg") into a drawing on a specific layer (lets call the layer "power"). The syntax should change the current drawing layer to "power" if it is not already current. This is in 2000i.
 
Here is a little code to get you started:
Code:
Public Sub Example()
    Dim currLayer As AcadLayer
    Dim thisLayer As AcadLayer
    Dim sLayerName As String
    Dim titleBlock As AcadBlockReference
    Dim sTitleBlock As String
    Dim pt(0 To 2) As Double
    Dim rScale As Double
    
    'Define the layer you want
    sLayerName = "power"
    'Store the current layer setting
    Set currLayer = ThisDrawing.ActiveLayer
    'Find and Switch Layers
    For Each thisLayer In ThisDrawing.Layers
        If thisLayer.Name Like sLayerName Then
            thisLayer.Freeze = False
            thisLayer.LayerOn = True
            ThisDrawing.ActiveLayer = thisLayer
            Exit Sub
        End If
    Next
    'Define the Block
    sTitleBlock = "Plug.dwg"
    'Insertion Point (5,10,0) and Scale (8)
    pt(0) = 5
    pt(1) = 10
    rScale = 8
    'Insert the Block
    Set titleBlock = ThisDrawing.ModelSpace.InsertBlock _
            (pt, sTitleBlock, rScale, rScale, 1#, 0#)
    
    'Restore the Previous Layer
    ThisDrawing.ActiveLayer = currLayer
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top