VBA or Python code examples or demo needed

I need to build a simple script
can somebody point me to a source for examples "commands with filenames as parameter"

-generate a new drawing
-import a pdf-file by full-name
- (some magik I know)
-zoom extents
-export all to svg by fullname

Comments

  • Hello.

    Something very basic would be like this:

    '————————————————

    Sub NewDrawing()
    Dim doc As AcadDocument
    Set doc = ThisDrawing.Application.Documents.Add
    End Sub

    '————————————————

    Sub ImportPDF()
    Dim doc As AcadDocument
    Set doc = ThisDrawing.Application.ActiveDocument

    Dim svFileDia As Integer
    svFileDia = ThisDrawing.GetVariable("FILEDIA")

    ThisDrawing.SetVariable "FILEDIA", 0

    Dim FileName As String
    FileName = "c:/temp/vba_import.pdf"

    Dim Page As Integer
    Page = 1

    Dim InsPt As String
    InsPt = "0,0"

    Dim IScale As Double
    IScale = 1

    Dim Rot As Double
    Rot = 0

    ThisDrawing.SendCommand "_-pdfimport" & vbCrLf _
    & "_f" & vbCrLf _
    & FileName & vbCrLf _
    & Page & vbCrLf _
    & InsPt & vbCrLf _
    & CStr(IScale) & vbCrLf _
    & CStr(Rot) & vbCrLf

    If svFileDia Then
    ThisDrawing.SetVariable "FILEDIA", svFileDia
    End If

    ThisDrawing.SendCommand "_zoom" & vbCrLf _
    & "_e" & vbCrLf

    End Sub

    '————————————————

    Sub ExportSvg()

    Dim svFileDia As Integer
    svFileDia = ThisDrawing.GetVariable("FILEDIA")

    ThisDrawing.SetVariable "FILEDIA", 0

    Dim SvgName As String
    SvgName = "c:/temp/vba_export.svg"

    ThisDrawing.SendCommand "_export" & vbCrLf _
    & SvgName & vbCrLf

    If svFileDia Then
    ThisDrawing.SetVariable "FILEDIA", svFileDia
    End If

    End Sub

    '————————————————

    Sub Main()
    NewDrawing
    ImportPDF
    ExportSvg
    End Sub

  • The same can be done in lisp as well. One thing that has been asked for pdf import is about importing a page or all pages in a multi page pdf and how to arrange.

  • You can find some samples in:

    C:\Program Files\Bricsys\BricsCAD V23 pt_BR\API

    Also, I would not recommend using VB or Python. C# has a lot of content over internet.

    Use the keywords: C# autocad the thing you want to do.