0

I'm programming on VBA for Autocad but until this day I can't found how to create or insert line on VB.NET.

I see that VB.NET have two kinds of concepts to use the acad files.

  1. Using: AcApplication.DocumentManager.MdiActiveDocument;

  2. Using some like this, as transaction for more than one file all files of folders are declared as database and the block table and modifications as transactions, maybe I'm a little lost on the concepts but I'm new in VB.NET

I'm need a sample of how to create line or circle on VB.NET and insert on DXF drawing using the concept 2 as database because I need to modify a lot of drawings.

For Each Filedxf As IO.FileInfo In Modfiles 
Try 
    Change = False 
    Dim MyDB As New Database(False, True) 
    MyDB.DxfIn(Filedxf.FullName.ToString, IO.Path.Combine(PathToChange, "dxf.log")) 
    Using MyTrans As Transaction = MyDB.TransactionManager.StartTransaction 
        Dim MyBT As BlockTable = MyDB.BlockTableId.GetObject(OpenMode.ForRead) 
        For Each MyBTRId As ObjectId In MyBT 
            Dim MyBTR As BlockTableRecord = MyBTRId.GetObject(OpenMode.ForRead) 
            For Each cadID As ObjectId In MyBTR 
                Select Case cadID.ObjectClass.DxfName.ToUpper 
                    Case "TEXT" 
                        Dim MyText As DBText = cadID.GetObject(OpenMode.ForWrite) 
                        Select Case MyText.Layer.ToUpper

Thanks a lot for your help

Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
Zeus Paez
  • 31
  • 3

2 Answers2

0

A good place to start is here

http://exchange.autodesk.com/autocad/enu/online-help/browse

Google inserting a line into the modelspace. Changing a layer propery, and transaction.GetObject()

That will give you a good start.

Trae Moore
  • 1,759
  • 3
  • 17
  • 32
0

The AutoCAD interop can be accessed by referencing the new ObjectARX dlls. The code for drawing lines, adding blocks or any other AutoCAD functions remains largely unchanged for the last few years.

Some of what you can do from VB:

Imports Autodesk.AutoCAD.Interop
Imports AutoCAD

'drawing lines
'Set start point x:y:z coordinates
Dim sPoint(2) As Double 'Declare start point
sPoint(0) = X1 : sPoint(1) = Y1 : sPoint(2) = Z1
'Set end point x:y:z coordinate
ePoint(0) = X2 : ePoint(1) = Y2 : ePoint(2) = Z2


'Drawing lines
temp = ThisDrawing.ModelSpace.AddLine(sPoint, ePoint)
'changing layer for new object
temp.Layer = "LONGDASH"

'setting layer
ThisDrawing.ActiveLayer = ThisDrawing.Layers.Item(11)

' Adding blocks
Dim dblRotate As Double

Dim temp As AcadBlockReference
'Call Block_Detector(blockName)
'convert rotation to radians
dblRotate = ThisDrawing.Utility.AngleToReal(CStr(dblRotation), AcAngleUnits.acDegrees) '* 3.141592 / 180#

sPoint(0) = X 'Set start point x coordinate
sPoint(1) = Y 'Set start point y coordinate
sPoint(2) = Z 'Set start point z coordinate

'Set temp = ThisDrawing.Blocks.Add(sPoint, blockName)
temp = ThisDrawing.ModelSpace.InsertBlock(sPoint, blockName, 1, 1, 1, dblRotate)

More information can be found at the AutoCAD Developer Guide

reckface
  • 5,678
  • 4
  • 36
  • 62