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

Newbie Q: Zoom E with VB.NET

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
732 Views, 8 Replies

Newbie Q: Zoom E with VB.NET

Folks,
I'm writing a VB.NET dll to act as a front-end for some Lisp routines. I
have the interface working and can produce drawings with the Lisp. How can I
finish up with a Zoom E without using SendStringToExecute? I've reviewed
post 452250 but can't quite make the conversion from C# to VB.NET.

Thanks in advance
BWA
8 REPLIES 8
Message 2 of 9
RonnieWilkins
in reply to: Anonymous

Please see the attached code...

Note that currently I have it working for model space only.
Ronnie Wilkins, Jr.
Message 3 of 9
RonnieWilkins
in reply to: Anonymous

Use the following attached code instead of the above...forgot to include the aced functions...
Ronnie Wilkins, Jr.
Message 4 of 9
Anonymous
in reply to: Anonymous

If your code is being called from the document context,
then you can just use the command line like this (sorry,
this is C#):

//////////////////////////////////////////////////////////////////
/// Commands.cs copyright (c) 2006 Tony Tanzillo

using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

public class Commands
{
Commands() {}

const string ACAD_EXE = "acad.exe";
const string ACDB_XX_DLL = "acdb16.dll";

const short RTSTR = 5005;
const short RTNORM = 5100;
const short RTNONE = 5000;
const short RTREAL = 5001;
const short RT3DPOINT = 5009;
const short RTLONG = 5010;
const short RTSHORT = 5003;
const short RTENAME = 5006;

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport(ACAD_EXE, CallingConvention = CallingConvention.Cdecl)]
extern static int acedCmd( IntPtr resbuf );

public static int Command(params object[] args)
{
if( AcadApp.DocumentManager.IsApplicationContext )
return 0;
int res = 0;
using( ResultBuffer buffer = new ResultBuffer() )
{
foreach( object o in args )
{
int code = 0;
if( o is string )
code = RTSTR;
else if( o is Int32 )
code = RTLONG;
else if( o is Int16 )
code = RTSHORT;
else if( o is double )
code = RTREAL;
else if( o is Point3d )
code = RT3DPOINT;
else if( o is ObjectId )
code = RTENAME;

if( code != 0 )
buffer.Add(new TypedValue(code, o));
}
if( buffer.AsArray().Length > 0 )
{
object cmdecho = AcadApp.GetSystemVariable("CMDECHO");
AcadApp.SetSystemVariable("CMDECHO", 0);
res = acedCmd(buffer.UnmanagedObject);
AcadApp.SetSystemVariable("CMDECHO", cmdecho);
}
}
return res;
}

public static int ZoomExtents()
{
return Command("._ZOOM", "_E");
}

}

///////////// Commands.cs ///////////////////////////////

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"bwa" wrote in message news:5097401@discussion.autodesk.com...
Folks,
I'm writing a VB.NET dll to act as a front-end for some Lisp routines. I
have the interface working and can produce drawings with the Lisp. How can I
finish up with a Zoom E without using SendStringToExecute? I've reviewed
post 452250 but can't quite make the conversion from C# to VB.NET.

Thanks in advance
BWA
Message 5 of 9
Anonymous
in reply to: Anonymous

Thanks for the reply. However, I'm getting an error in the "Public Shared
Function GetExtents..." that indicates that 'Name Using is not declared.'
Is there an import or reference that may not have been included in your code
sample?

BWA

wrote in message news:5097756@discussion.autodesk.com...
Use the following attached code instead of the above...forgot to include the
aced functions...
Message 6 of 9
Anonymous
in reply to: Anonymous

Tony,
I'm not at all familiar with C#, and in fact I'm very new to VB.NET. It's
going to take a bit but you've provided an interesting example that I'm sure
I'll have to spend some time playing with.

Thanks,
BWA

"Tony Tanzillo" wrote in message
news:5098060@discussion.autodesk.com...
If your code is being called from the document context,
then you can just use the command line like this (sorry,
this is C#):
Message 7 of 9
Anonymous
in reply to: Anonymous

The 'Using' keyword is not available in VS 2002, only
2003 and later.

If you're new to VB.NET, I would suggest you consider
learning C# rather than VB. The reason is that you'll
find that most of the C# code and examples you find
are on the average, of better quality than the average
VB.NET code.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"bwa" wrote in message news:5098476@discussion.autodesk.com...
Thanks for the reply. However, I'm getting an error in the "Public Shared
Function GetExtents..." that indicates that 'Name Using is not declared.'
Is there an import or reference that may not have been included in your code
sample?

BWA

wrote in message news:5097756@discussion.autodesk.com...
Use the following attached code instead of the above...forgot to include the
aced functions...
Message 8 of 9
RonnieWilkins
in reply to: Anonymous

GetExtents function redone using Try/Catch/Finally instead of Using
Ronnie Wilkins, Jr.
Message 9 of 9
RonnieWilkins
in reply to: Anonymous

Using a great translator utility (http://authors.aspalliance.com/aldotnet/examples/translate.aspx) here is Tony's example converted to VB.NET



'////////////////////////////////////////////////////////////////< br>/// Commands.cs copyright (c) 2006 Tony Tanzillo
Imports System
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application

_

Public Class Commands

Sub New()
End Sub 'New
Private ACAD_EXE As String = "acad.exe"
Private ACDB_XX_DLL As String = "acdb16.dll"

Private RTSTR As Short = 5005
Private RTNORM As Short = 5100
Private RTNONE As Short = 5000
Private RTREAL As Short = 5001
Private RT3DPOINT As Short = 5009
Private RTLONG As Short = 5010
Private RTSHORT As Short = 5003
Private RTENAME As Short = 5006


Shared _
Function acedCmd(resbuf As IntPtr) As Integer


Public Shared Function Command(ParamArray args() As Object) As Integer
If AcadApp.DocumentManager.IsApplicationContext Then
Return 0
End If
Dim res As Integer = 0
Dim buffer As New ResultBuffer()
Try
Dim o As Object
For Each o In args
Dim code As Integer = 0
If TypeOf o Is String Then
code = RTSTR
Else
If TypeOf o Is Int32 Then
code = RTLONG
Else
If TypeOf o Is Int16 Then
code = RTSHORT
Else
If TypeOf o Is Double Then
code = RTREAL
Else
If TypeOf o Is Point3d Then
code = RT3DPOINT
Else
If TypeOf o Is ObjectId Then
code = RTENAME
End If
End If
End If
End If
End If
End If
If code <> 0 Then
buffer.Add(New TypedValue(code, o))
End If
Next o
If buffer.AsArray().Length > 0 Then
Dim cmdecho As Object = AcadApp.GetSystemVariable("CMDECHO")
AcadApp.SetSystemVariable("CMDECHO", 0)
res = acedCmd(buffer.UnmanagedObject)
AcadApp.SetSystemVariable("CMDECHO", cmdecho)
End If
Finally
buffer.Dispose()
End Try
Return res
End Function 'Command


Public Shared Function ZoomExtents() As Integer
Return Command("._ZOOM", "_E")
End Function 'ZoomExtents
End Class 'Commands

'/////////// Commands.cs ///////////////////////////////
Ronnie Wilkins, Jr.

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