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

SendStringToExecute

13 REPLIES 13
Reply
Message 1 of 14
Hans530
10245 Views, 13 Replies

SendStringToExecute

Hi Everybody

When the code below are executed the line, drawing the line are executed after the rest of the code,

that is the msgboxes are displayed before the line are drawn in Acad_Window.

what should be done to display the  msgboxes before the line, as the order in the code indicates

Hope someone has an explanation and solution to this

With Regards

HansP

''

Application.DocumentManager.MdiActiveDocument.SendStringToExecute("line_

1800,2001600,3000 ", True, False, True)

MsgBox("DWG Saved")

dwgPath = ThisDrawing.GetVariable("DWGPREFIX")

dwgName = ThisDrawing.GetVariable("DWGNAME")

Dim thisDwg AsString = dwgPath + dwgName

MsgBox(thisDwg)

13 REPLIES 13
Message 2 of 14
norman.yuan
in reply to: Hans530

What you should do is to use the .NET API to

 

  • Start a Transaction
  • Construct a Line object, such as:

  Dim l as Line=New Line

  Line.StartPoint=New Point3d(....)

  Line.EndPoint=New Point3d(...)

 

  • Set the line's properties as needed
  • Append the line to targeting space (Model or layout)
  • Commit the transaction

You can create a command method to cover all the steps aforemention, and then use SendStringToExecution() method as one call.

 

If the intention is to use all Acad existing/built-in commands, use AutoCAD script would do in most cases.

Message 3 of 14
Hans530
in reply to: Hans530

Thank you for your quick responce

 

The line worked fine, but how to do with a zoom command.

 

Hans P

Message 4 of 14
ranjith0326
in reply to: Hans530

Try with below one

 

Application.DocumentManager.MdiActiveDocument.SendStringToExecute("zoom e ", True, False, True)

Regards,

R.Ranjith
Message 5 of 14
Alexander.Rivilis
in reply to: Hans530


@Hans530 wrote:

The line worked fine, but how to do with a zoom command.

 


http://forums.autodesk.com/t5/NET/ZoomWindow-and-ZoomScale/m-p/3249340#M26321

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 6 of 14
Hans530
in reply to: Alexander.Rivilis

 

 

I do not know anything about C# so, I translated the ZoomExtents like this. It compiled OK but there was a runtime error complaining about the BindingFlags. As I don’t know any C# and as it seems not enough VB either to translate that part of the code where several BindingFlags are listid. I must ask for further help with that part

Thanks in advance Hans P

 

public static void ZoomExtents()

    {

        object acad = Application.AcadApplication;

        acad.GetType().InvokeMember("ZoomExtents", BindingFlags.DeclaredOnly | BindingFlags.Public |

             BindingFlags.Instance | BindingFlags.InvokeMethod, null, acad, null);

    }

 

 

 

 

Public Sub ZoomExtents()

Dim acad As Object = Application.AcadApplication

acad.GetType().InvokeMember("ZoomExtents",BindingFlags.DeclaredOnly, Nothing, acad, Nothing)

End Sub

Message 7 of 14
Alexander.Rivilis
in reply to: Hans530

Imports System.Reflection

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 8 of 14
Hans530
in reply to: Alexander.Rivilis

Imports System.Reflection

I had that one without that it wouldn't compile

But is the row

acad.GetType().InvokeMember("ZoomExtents",BindingFlags.DeclaredOnly, Nothing, acad, Nothing)

translated ok from C#

 

 Hans P

Message 9 of 14
Alexander.Rivilis
in reply to: Hans530

acad.GetType().InvokeMember("ZoomExtents",BindingFlags.InvokeMethod, Nothing, acad, Nothing)

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 10 of 14
_gile
in reply to: Alexander.Rivilis

Hi,

 

While using Reflection/Late binding, we can use some (extension) methods to make the code more readable than the :

GetType().InvokeMember(...)

 

With C# and Framework 3.5 or upper, we can write some extension methods so that the upper expression to ma make zoom extents become:

acad.Invoke("ZoomExtents");

or, to set the cursor size to 10:

acad.Get("Preferences").Get("Display").Set("CursorSize", 10);

 

public static class LateBinding
{
	public static object Get(this object obj, string propName, params object[] parameter)
	{
		return obj.GetType().InvokeMember(propName, BindingFlags.GetProperty, null, obj, parameter);
	}

	public static void Set(this object obj, string propName, params object[] parameter)
	{
		obj.GetType().InvokeMember(propName, BindingFlags.SetProperty, null, obj, parameter);
	}

	public static object Invoke(this object obj, string methName, params object[] parameter)
	{
		return obj.GetType().InvokeMember(methName, BindingFlags.InvokeMethod, null, obj, parameter);
	}
}

 

With F#, it's really easy to extend any Type, but ther's no way (AFAIK) to use optional parameters (as with params or ParamArray), but creating an array is so simple.

The zoom extents:

acad.invoke("ZoomExtents", null) |> ignore

The cursor to 10:
let size = acad.get("Preferences", null).get("Display", null).set("CursorSize", [| 10 |])

 

type Object with
    member x.get(propName, parameter) = 
        x.GetType().InvokeMember(propName, BindingFlags.GetProperty, null, x, parameter)

    member x.set(propName, parameter) = 
        x.GetType().InvokeMember(propName, BindingFlags.SetProperty, null, x, parameter)
        |> ignore

    member x.invoke (propName, parameter) = 
        x.GetType().InvokeMember(propName, BindingFlags.InvokeMethod, null, x, parameter)

 

VB do not allow to use extension methods with the Object Type, but we can define methods so that late binding expressions look like the vlax-get, vlax-put, and vlax,invoke LISP functions.

The zoom extents:

Invoke(acad, "ZoomExtents")

The cursor to 10:
SetProperty(GetProperty(GetProperty(acad, "Preferences"), "Display"), "CursorSize", 10)

 

Module LateBindingExtensions

    Public Function GetProperty(ByVal obj As Object, ByVal propName As String, ByVal ParamArray parameter As Object()) As Object
        Return obj.GetType().InvokeMember(propName, BindingFlags.GetProperty, Nothing, obj, parameter)
    End Function

    Public Sub SetProperty(ByVal obj As Object, ByVal propName As String, ByVal ParamArray parameter As Object())
        obj.GetType().InvokeMember(propName, BindingFlags.SetProperty, Nothing, obj, parameter)
    End Sub

    Public Function Invoke(ByVal obj As Object, ByVal methName As String, ByVal ParamArray parameter As Object()) As Object
        Return obj.GetType().InvokeMember(methName, BindingFlags.InvokeMethod, Nothing, obj, parameter)
    End Function

End Module

 




Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 14
_gile
in reply to: _gile

Another way using F# is to define three functions so that the arguments order allows to use the "pipe forward" operator (|>).

 

let get prop param obj =
    obj.GetType().InvokeMember(prop, BindingFlags.GetProperty, null, obj, param)

let set prop param obj =
    obj.GetType().InvokeMember(prop, BindingFlags.SetProperty, null, obj, param) |> ignore

let invoke meth param obj =
    obj.GetType().InvokeMember(meth, BindingFlags.InvokeMethod, null, obj, param)

[<CommandMethod("foo")>]
let foo() =
    let acad = Application.AcadApplication
    acad |> invoke "ZoomExtents" null |> ignore
    acad |> get "Preferences" [||] |> get "Display" [||] |> set "CursorSize" [| 5 |]

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 12 of 14
Hans530
in reply to: _gile

Thank you all for your responce

Hans P

Message 13 of 14
mmsiva1983
in reply to: Hans530

cadApp.GetType().InvokeMember("ZoomExtents", BindingFlags.InvokeMethod, null, cadApp, null);

Message 14 of 14
BKSpurgeon
in reply to: Hans530

why use string to execute when you can do this:

 

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUI...

 

code which draws a line.

 

 

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