.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

help moving vba to vb

6 REPLIES 6
Reply
Message 1 of 7
Anonymous
438 Views, 6 Replies

help moving vba to vb

I have about a 100 VBA routines that I need to convert to VB but need help
getting started. Until I can truly convert my routines to dot net one by
one (still learning) I'd like to be able to still use them in vb if
possible. It appears but I could be wrong if I can get access to the
thisdrawing most of my routines could still run. (hoping) virtually all my
routines simply draw polylines of varying shapes and layers.

Any help you can provide on what references need to be assigned to get
thisdrawing function or am I out of luck until I learn dot net. Below is
basically what I'm trying convert. pick a point, set a direction, turn some
angles from direction, draw ployline.

Have a great day,

John Coon

Imports System

Imports Autodesk.AutoCAD.Interop

Imports Autodesk.AutoCAD.Interop.Common

Dim dblRot As Double

Dim point1 As Variant

Dim point2 As Variant

Dim point100 As Variant

Dim point101 As Variant

Dim point102 As Variant

Dim pi As Double

Dim ThisDrawing As AcadDocument

ThisDrawing = DocumentManager.MdiActiveDocument.AcadDocument 'this is not
working

Dim layerObj As AcadLayer

layerObj = ThisDrawing.Layers.Add("C-STRP")

ThisDrawing.ActiveLayer = layerObj

objWCS = ThisDrawing.UserCoordinateSystems.Add(dblOrigin, dblXVector,
dblYVector, "WCS")

ThisDrawing.ActiveUCS = objWCS

'point1 = ThisDrawing.Utility.GetPoint(, "Pick Centerline Start Location,")

'point2 = ThisDrawing.Utility.GetPoint(point1, "Select Direction Mid point")

point1(0) = 0.0

point1(1) = 0.0

point2(0) = 500.0

point2(1) = 0.0

dblRot = ThisDrawing.Utility.AngleFromXAxis(point1, point2)

Dim rw1, rw2, rwdist As Double

rw1 = point1(0) - point2(0)

rw2 = point1(1) - point2(1)

rwdist = Math.Sqrt(rw1 ^ 2 + rw2 ^ 2)

'MsgBox("dist is = " & rwdist)

point100 = ThisDrawing.Utility.PolarPoint(point1, (pi + dblrot), -50)
point101 = ThisDrawing.Utility.PolarPoint(point100, (pi + dblrot), -50)
point102 = ThisDrawing.Utility.PolarPoint(point100, (pi + dblrot),50)


Dim DRWPOLY As AcadLWPolyline
Dim points(3) As Double
points(0) = point101(0): points(1) = point101(1)
points(2) = point102(0): points(3) = point102(1)
Set DRWPOLY = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

Hello,

I am in the same situation you are with .NET programming. About all we can do is dive right in.
Your references appear to be correct for the ActiveX/COM API.
Next, you do this:

Dim app As Autodesk.AutoCAD.Interop.AcadApplication
Dim doc As Autodesk.AutoCAD.Interop.AcadDocument
' I am getting the AutoCAD 2009 application with this number 17. Your number may vary.
app = GetObject(, "AutoCAD.Application.17")
doc = app.ActiveDocument

The variable 'doc' is now the equivalent of ThisDrawing in VBA.
Hope that helps!
Message 3 of 7
Anonymous
in reply to: Anonymous


Thanks for the help.

 

When I insert your sample I still
get error on thisdrawing

 


color=#0000ff>dim
app
color=#0000ff>As

Autodesk.AutoCAD.Interop.AcadApplication



color=#0000ff>Dim
doc
color=#0000ff>As

Autodesk.AutoCAD.Interop.AcadDocument


app = GetObject(,
color=#a31515>
color=#a31515>"AutoCAD.Application.17"

face=Arial>)


doc = app.ActiveDocument


 


but if I change



color=#008000 size=2>

Dim app As Autodesk.AutoCAD.Interop.AcadApplication


size=2>

Dim ThisDrawing As
Autodesk.AutoCAD.Interop.AcadDocument


app = GetObject(,
"AutoCAD.Application.17")


ThisDrawing =
app.ActiveDocument


I get thisdrawing control but
recieve error on app. this is the only line in 1000 lines that shows as an
error


John
Coon


size=2>

 

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hello,
I am in the same situation you are with .NET programming. About all we can do
is dive right in. Your references appear to be correct for the ActiveX/COM
API. Next, you do this: Dim app As Autodesk.AutoCAD.Interop.AcadApplication
Dim doc As Autodesk.AutoCAD.Interop.AcadDocument ' I am getting the AutoCAD
2009 application with this number 17. Your number may vary. app = GetObject(,
"AutoCAD.Application.17") doc = app.ActiveDocument The variable 'doc' is now
the equivalent of ThisDrawing in VBA. Hope that
helps!
Message 4 of 7
Anonymous
in reply to: Anonymous



I
removed the thisdrawing and it appears to be
working.

Thanks for all your help!

 


color=#0000ff>dim
app
color=#0000ff>As

Autodesk.AutoCAD.Interop.AcadApplication



color=#0000ff>Dim
doc
color=#0000ff>As

Autodesk.AutoCAD.Interop.AcadDocument


app = GetObject(,
color=#a31515>
color=#a31515>"AutoCAD.Application.17"

face=Arial>)


doc = app.ActiveDocument


 


 


 

 

 

 

 

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


Thanks for the help.

 

When I insert your sample I still
get error on thisdrawing

 


color=#0000ff>dim
app
color=#0000ff>As

Autodesk.AutoCAD.Interop.AcadApplication



color=#0000ff>Dim
doc
color=#0000ff>As

Autodesk.AutoCAD.Interop.AcadDocument


app = GetObject(,
color=#a31515>
color=#a31515>"AutoCAD.Application.17"

face=Arial>)


doc = app.ActiveDocument


 


but if I change



color=#0000ff>

Dim app As Autodesk.AutoCAD.Interop.AcadApplication


size=2>

Dim ThisDrawing As
Autodesk.AutoCAD.Interop.AcadDocument


app = GetObject(,
"AutoCAD.Application.17")


ThisDrawing =
app.ActiveDocument


I get thisdrawing control but
recieve error on app. this is the only line in 1000 lines that shows as an
error


John
Coon


face=Arial size=2>

 

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hello,
I am in the same situation you are with .NET programming. About all we can
do is dive right in. Your references appear to be correct for the
ActiveX/COM API. Next, you do this: Dim app As
Autodesk.AutoCAD.Interop.AcadApplication Dim doc As
Autodesk.AutoCAD.Interop.AcadDocument ' I am getting the AutoCAD 2009
application with this number 17. Your number may vary. app = GetObject(,
"AutoCAD.Application.17") doc = app.ActiveDocument The variable 'doc' is now
the equivalent of ThisDrawing in VBA. Hope that
helps!
Message 5 of 7
Anonymous
in reply to: Anonymous

You don't use GetObject() to get the application object.

You get it the way your code originally was doing that, from
the MdiActiveDocument.AcadDocument property.

When you come here for help, you should be more specific than 'this is not
working', or 'an error occurs'.

State exactly what isn't working or what error message you get.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


"john coon" wrote in message
news:6157541@discussion.autodesk.com...
I removed the thisdrawing and it appears to be working.
Thanks for all your help!

dim app As Autodesk.AutoCAD.Interop.AcadApplication
Dim doc As Autodesk.AutoCAD.Interop.AcadDocument

app = GetObject(, "AutoCAD.Application.17")

doc = app.ActiveDocument












"john coon" wrote in message
news:6157540@discussion.autodesk.com...
Thanks for the help.

When I insert your sample I still get error on thisdrawing

dim app As Autodesk.AutoCAD.Interop.AcadApplication
Dim doc As Autodesk.AutoCAD.Interop.AcadDocument

app = GetObject(, "AutoCAD.Application.17")

doc = app.ActiveDocument



but if I change

Dim app As Autodesk.AutoCAD.Interop.AcadApplication

Dim ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument

app = GetObject(, "AutoCAD.Application.17")

ThisDrawing = app.ActiveDocument

I get thisdrawing control but recieve error on app. this is the only line
in 1000 lines that shows as an error

John Coon




wrote in message
news:6157471@discussion.autodesk.com...
Hello, I am in the same situation you are with .NET programming. About
all we can do is dive right in. Your references appear to be correct for the
ActiveX/COM API. Next, you do this: Dim app As
Autodesk.AutoCAD.Interop.AcadApplication Dim doc As
Autodesk.AutoCAD.Interop.AcadDocument ' I am getting the AutoCAD 2009
application with this number 17. Your number may vary. app = GetObject(,
"AutoCAD.Application.17") doc = app.ActiveDocument The variable 'doc' is now
the equivalent of ThisDrawing in VBA. Hope that helps!
Message 6 of 7
Anonymous
in reply to: Anonymous

Thanks for the advice, Tony!
I forget where I saw an example to use GetObject for the Application, but I'm going to change the way I do it.
Message 7 of 7
Anonymous
in reply to: Anonymous

Tony,

Thank you,

Sorry about the short note but in dot net I was lost as to what was causing
the error, was it because I did have the correct references or
was I asking for objects that I didn't have access to. I just wasn't sure
where to start or where to look.

I wrote down /saw somewhere last week about setting the This =
DocumentManager.MdiActiveDocument.AcadDocument and that could
give me access to the thisdrawing so I could start to convert some of my
routines until I learned how to do them correctly from scratch in dot net.

I thought if I had access to the Thisdrawing I might be able to test / learn
with routines I already know so it might allow me to learn how to get
started
in dot net.

Without the connect to AutoCAD like in VBA it seems difficult for new people
to get up and running like me. After I can do that I'm sure I'll be able to
progress.


Thanks, Have a great day.

John Coon


"Tony Tanzillo" wrote in message
news:6157657@discussion.autodesk.com...
You don't use GetObject() to get the application object.

You get it the way your code originally was doing that, from
the MdiActiveDocument.AcadDocument property.

When you come here for help, you should be more specific than 'this is not
working', or 'an error occurs'.

State exactly what isn't working or what error message you get.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


"john coon" wrote in message
news:6157541@discussion.autodesk.com...
I removed the thisdrawing and it appears to be working.
Thanks for all your help!

dim app As Autodesk.AutoCAD.Interop.AcadApplication
Dim doc As Autodesk.AutoCAD.Interop.AcadDocument

app = GetObject(, "AutoCAD.Application.17")

doc = app.ActiveDocument












"john coon" wrote in message
news:6157540@discussion.autodesk.com...
Thanks for the help.

When I insert your sample I still get error on thisdrawing

dim app As Autodesk.AutoCAD.Interop.AcadApplication
Dim doc As Autodesk.AutoCAD.Interop.AcadDocument

app = GetObject(, "AutoCAD.Application.17")

doc = app.ActiveDocument



but if I change

Dim app As Autodesk.AutoCAD.Interop.AcadApplication

Dim ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument

app = GetObject(, "AutoCAD.Application.17")

ThisDrawing = app.ActiveDocument

I get thisdrawing control but recieve error on app. this is the only line
in 1000 lines that shows as an error

John Coon




wrote in message
news:6157471@discussion.autodesk.com...
Hello, I am in the same situation you are with .NET programming. About
all we can do is dive right in. Your references appear to be correct for the
ActiveX/COM API. Next, you do this: Dim app As
Autodesk.AutoCAD.Interop.AcadApplication Dim doc As
Autodesk.AutoCAD.Interop.AcadDocument ' I am getting the AutoCAD 2009
application with this number 17. Your number may vary. app = GetObject(,
"AutoCAD.Application.17") doc = app.ActiveDocument The variable 'doc' is now
the equivalent of ThisDrawing in VBA. Hope that helps!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost