Author Topic: Create Programming Object  (Read 5346 times)

0 Members and 1 Guest are viewing this topic.

jtoverka

  • Newt
  • Posts: 127
Create Programming Object
« on: September 20, 2019, 10:11:38 AM »
Every time I search for this (on google), I get "how to create line object" or something equivalent. I am NOT looking to make AutoCAD objects. I want to create objects from a class defined in C#.NET. From LISP I want to use vlax-create-object or something equivalent to create the object. Furthermore use vlax-put-property, vlax-get-property, and vlax-invoke-method with this object (or something equivalent).

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Create Programming Object
« Reply #1 on: September 20, 2019, 07:23:44 PM »
Here's a starting point: https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-3B2760FE-A0DC-4229-AEBE-5CC83290BA95-htm.html

To create/use 'objects' (i.e. classes) from .net you need to pass a result buffer to/from .net, this result buffer holds the parameter data for creating objects or using functions. You also pass data back via result buffers.
For example, you have a lisp method in C# that creates an object, you create the object from Lisp by calling the Lisp method and passing the constructor parameters in a result buffer. When this gets called in C# you unpack the result buffer and create the object using those parameters. You might pass the handle or object id back via a returned result buffer so you can have access to the new object for other functions.

The vlax- Lisp functions are for ActiveX (i.e. COM) and if you want to use those functions you need to build/wrap your .net classes for COM.

hth
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

jtoverka

  • Newt
  • Posts: 127
Re: Create Programming Object
« Reply #2 on: September 28, 2019, 10:49:49 AM »
So my end goal is to convert these AutoLISP functions to .NET:

Code: [Select]
(vl-load-com)
(setq CUSTOM_FNAM (strcat "C:/Users/" (getvar 'loginname) "/Desktop/Action_tile.lsp"))


(defun *error* (msg)
(princ "Error: ")
(princ msg)
(princ)
)

(defun readFunctionPrint (str / JO_file)
(if
  (and
CUSTOM_FNAM
(setq JO_file (f_open CUSTOM_FNAM "a"))
  )
  (progn
(princ str JO_file)
(f_close JO_file)
  )
)
)

(if (not f_close)
  (progn
(setq f_close close)
(and (not f_open) (setq f_open open))
(setq close
(lambda (file / JO_file)
(if
  (and
CUSTOM_FNAM
(setq JO_file (f_open CUSTOM_FNAM "a"))
  )
  (progn
(princ (strcat "(close " (vl-prin1-to-string file) ")") JO_file)
(princ "\n" JO_file)
(f_close JO_file)
  )
)
(f_close file)
)
)
  )
)

(if (not f_open)
  (progn
(setq f_open open)
(and (not f_close) (setq f_close close))
(setq open
(lambda (key action / JO_file)
(if
  (and
CUSTOM_FNAM
(setq JO_file (f_open CUSTOM_FNAM "a"))
  )
  (progn
(princ (strcat "(open " (vl-prin1-to-string key)) JO_file)
(princ " " JO_file)
(princ (strcat (vl-prin1-to-string action) ")") JO_file)
(princ "\n" JO_file)
(f_close JO_file)
  )
)
(f_open key action)
)
)
  )
)

(if (not f_action_tile)
  (progn
(setq f_action_tile action_tile)
(setq action_tile
(lambda (key action / JO_file)
(if
  (and
CUSTOM_FNAM
(setq JO_file (f_open CUSTOM_FNAM "a"))
  )
  (progn
(princ (strcat "(action_tile " (vl-prin1-to-string key)) JO_file)
(princ "\n\t" JO_file)
(princ (strcat (vl-prin1-to-string action) "\n)") JO_file)
(princ "\n" JO_file)
(f_close JO_file)
  )
)
(f_action_tile key (strcat action "(readFunctionPrint (strcat \"(set_tile " key " $value) ; \" $value \"\n\"))"))
)
)
  )
)


This code will read all of the code within dialog boxes that work with AutoLISP.

The problem with AutoLISP is that you cannot create optional arguments to functions. In .NET you can and so that is what I am trying to do here. However, I am not familiar with C#.NET with AutoCAD so I am struggling. I need to find a way to export the function name, its arguments, and its result after execution as a comment in a text file.

I would like a way to simply provide a function as an argument to a .NET function. With an anonymous function as a return. This anonymous function will be stored in the symbol of the original function. This function will both invoke the original function and export the data to a file.

I am trying to do this with objects in .NET, based on your description, it seems I cannot do this with objects.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Create Programming Object
« Reply #3 on: September 28, 2019, 10:55:55 AM »
The problem with AutoLISP is that you cannot create optional arguments to functions.

Use lists.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

jtoverka

  • Newt
  • Posts: 127
Re: Create Programming Object
« Reply #4 on: September 28, 2019, 11:04:59 AM »
The problem with AutoLISP is that you cannot create optional arguments to functions.

Use lists.

This will not work for my application. I cannot change code that AutoDesk wrote.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Create Programming Object
« Reply #5 on: September 28, 2019, 11:10:02 AM »
The problem with AutoLISP is that you cannot create optional arguments to functions.

Use lists.

This will not work for my application. I cannot change code that AutoDesk wrote.

You don't have to, you need only pre-process before invoking native functions.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

jtoverka

  • Newt
  • Posts: 127
Re: Create Programming Object
« Reply #6 on: September 28, 2019, 11:19:49 AM »
The problem with AutoLISP is that you cannot create optional arguments to functions.

Use lists.

This will not work for my application. I cannot change code that AutoDesk wrote.

You don't have to, you need only pre-process before invoking native functions.

I would appreciate more clarity, are you talking about using AutoLISP or .NET?

Assuming .NET do you mean that I should:
1 Take the result buffer and go through each argument
2 put each argument into a list
3 return list?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Create Programming Object
« Reply #7 on: September 28, 2019, 11:25:53 AM »
I would appreciate more clarity, are you talking about using AutoLISP or .NET?

Assuming .NET do you mean that I should:
1 Take the result buffer and go through each argument
2 put each argument into a list
3 return list?

I was talking LISP. While you can do 1..3 above and there's utility therein for many things I believe it's overkill to overcome "LISP functions that don't take optional arguments".
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

jtoverka

  • Newt
  • Posts: 127
Re: Create Programming Object
« Reply #8 on: September 28, 2019, 11:41:49 AM »
I would appreciate more clarity, are you talking about using AutoLISP or .NET?

Assuming .NET do you mean that I should:
1 Take the result buffer and go through each argument
2 put each argument into a list
3 return list?

I was talking LISP. While you can do 1..3 above and there's utility therein for many things I believe it's overkill to overcome "LISP functions that don't take optional arguments".

The problem with AutoLISP is that you cannot create optional arguments to functions.

Use lists.

That is still not possible with my application. I cannot pre-process this data without having a function that allows optional arguments.

for example:
Code: [Select]
(done_dialog [status])

There are two combinations of this function. I cannot create a function in AutoLISP to replace done_dialog. I cannot use AutoLISP to achieve this period. You cannot pre-process this data and put it into a list because the function used to pre-process this is a fixed number of arguments.

You must use .NET for this application to create a function that allows optional arguments. This will allow a function like done_dialog to be executed and write this to a text file.

I am sure there is a way to have a combination of AutoLISP and .NET that can be used.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Create Programming Object
« Reply #9 on: September 28, 2019, 11:52:42 AM »
That is still not possible with my application. I cannot pre-process this data without having a function that allows optional arguments.

for example:
Code: [Select]
(done_dialog [status])

There are two combinations of this function.

<nodding>

I cannot create a function in AutoLISP to replace done_dialog. I cannot use AutoLISP to achieve this period. You cannot pre-process this data and put it into a list because the function used to pre-process this is a fixed number of arguments.

Therein lie the problem. Show me an example of your pre-process that invokes done_dialog.

You must use .NET for this application to create a function that allows optional arguments.

Sorry, still not convinced.

I hope you interpret my involvement herein as an attempt to clarify & help.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

jtoverka

  • Newt
  • Posts: 127
Re: Create Programming Object
« Reply #10 on: September 28, 2019, 12:04:48 PM »
Instead of reading one line out of my huge post and post a canned response to that line and digging your heels over it, why don't you read the whole thing?

I already posted code so take a look at that and you will find out why it is not possible to do what you are asking.
I have posted a function for action_tile because action_tile only takes two arguments. I cannot do this with done_dialog because it has optional arguments and you will not be able to prove me wrong.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Create Programming Object
« Reply #11 on: September 29, 2019, 12:38:35 PM »
Apologies, I did fail to note you're re-defining the native action_tile function via (setq action_tile (lambda ( key action ) ...).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

jtoverka

  • Newt
  • Posts: 127
Re: Create Programming Object
« Reply #12 on: September 29, 2019, 07:38:43 PM »
It's okay, I apologize if I came across as condescending.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Create Programming Object
« Reply #13 on: September 30, 2019, 08:18:49 AM »
No worries, understandable. Doubtful l’d be more diplomatic if the roles were reversed.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Create Programming Object
« Reply #14 on: October 01, 2019, 04:30:08 AM »
...<snip>...

There are two combinations of this function. I cannot create a function in AutoLISP to replace done_dialog. I cannot use AutoLISP to achieve this period. You cannot pre-process this data and put it into a list because the function used to pre-process this is a fixed number of arguments.

You must use .NET for this application to create a function that allows optional arguments. This will allow a function like done_dialog to be executed and write this to a text file.

I am sure there is a way to have a combination of AutoLISP and .NET that can be used.

This shouldn't be a problem, this is done by providing defaults for some of the parameters, to work out which ones are what in your result buffer is your task to sort out. Perhaps you can create more than one function, like one for each possible set of arguments?

https://www.google.com/search?q=c%23+optional+arguments&oq=c%23+optional+arguments&aqs=chrome..69i57j0l3j69i58j69i60.5663j0j4&sourceid=chrome&ie=UTF-8

If you still think COM (ActiveX for vlax_ functions) is what you want, these links may help:
https://www.google.com/search?sxsrf=ACYBGNQUZ9uaHuuiGPeuTXYFzKNcIrhb2A%3A1569918489490&ei=GQ6TXe7EHcyS9QPxkbuwBg&q=c%23+com+interface&oq=c%23+com+interface&gs_l=psy-ab.1.9.0i7i30l9j0.4512.12547..17476...0.2..0.166.663.0j4......0....1..gws-wiz.......0i71j35i39j0i22i30j0i20i263.ZE6sl6D2j2k
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien