Author Topic: Calling arx function from vb/a  (Read 4313 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Calling arx function from vb/a
« on: April 20, 2009, 05:29:15 AM »
Hi All,

I would like to call an arx function from vb or vba and pass an array of object ids or handles as an parameter, is this possible or is there another way to do this??

Here's what I have so far which is pretty rough but should give you an idea what I'm after.

Code: [Select]
'create the dll function def:
Private Declare Function MoveObjects Lib _
    "C:\\Dev\\test.arx" Alias "DCSMoveObjects" (ByRef ids() As Variant)

Public Sub ArxSubTest()
Dim Ent As AcadEntity
Dim ssetObj As AcadSelectionSet
Dim ids(100) As Variant 'this will need a ReDim or similar
Dim i As Integer

On Error Resume Next
thisdrawing.SelectionSets("prev").Delete
Set ssetObj = thisdrawing.SelectionSets.Add("prev")
ssetObj.SelectOnScreen

For Each Ent In ssetObj
     ids(i) = Ent.ObjectId
     i = i+1
Next

'dump 'em:
MoveObjects ids

End Sub

and the arx function sig is -

void DCSMoveObjects (AcDbObjectIdArray* ids);

- and is exported from the arx(dll) and with testing can be called with no arg's but that's not very useful for my needs and was only for testing.

thanks.
Mick.

P.S. I know I can do the sset in the arx but I may need to get the id's from another source other than user selection.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Calling arx function from vb/a
« Reply #1 on: April 20, 2009, 07:27:41 AM »
Can you make the ARX function exposed to lisp then evaluate the lisp through VBA hehe. Luis is getting really good at that com stuff, maybe he can help  :-)

Chuck Gabriel

  • Guest
Re: Calling arx function from vb/a
« Reply #2 on: April 20, 2009, 08:35:33 AM »
Mick,

This is from something I wrote a long time ago, and I it looks like I implemented it as an ATL class (though that isn't how I remembered it), but it might give you some clues on how to handle an array.

Spike Wilbury

  • Guest
Re: Calling arx function from vb/a
« Reply #3 on: April 20, 2009, 10:48:44 AM »
Can you make the ARX function exposed to lisp then evaluate the lisp through VBA hehe. Luis is getting really good at that com stuff, maybe he can help  :-)

I might, be able to write something later today (in ATL, but I see that Chuck already post something) let me know.... but today, I just started on my new job, so I will be just reading what's going on here.... :-)

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Calling arx function from vb/a
« Reply #4 on: April 20, 2009, 04:27:11 PM »
Thanks Guys.

Chuck, I will absorb that a bit later, I was really trying to avoid COM as I may have 64 bit issues later down the track but from what I understand I can still call a dll from vb/a ... but I'm only speculating :)

Worst case scenario I will write the id's/handles to a file and open it from arx which should avoid these issues.

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

Spike Wilbury

  • Guest
Re: Calling arx function from vb/a
« Reply #5 on: April 21, 2009, 09:43:11 AM »
Thanks Guys.

Chuck, I will absorb that a bit later, I was really trying to avoid COM as I may have 64 bit issues later down the track but from what I understand I can still call a dll from vb/a ... but I'm only speculating :)

Worst case scenario I will write the id's/handles to a file and open it from arx which should avoid these issues.

cheers,
Mick.

Hi Mick,

Here is an example, with two functions, and if you need a Visual Studio ATL solution sample let me know.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Calling arx function from vb/a
« Reply #6 on: April 21, 2009, 04:13:57 PM »
Thanks Luis.

Can I just add an ATL object to my arx project for this to work or do I need to set up a new project for a COM interface complete with idl file?
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Spike Wilbury

  • Guest
Re: Calling arx function from vb/a
« Reply #7 on: April 21, 2009, 04:26:12 PM »
Thanks Luis.

Can I just add an ATL object to my arx project for this to work or do I need to set up a new project for a COM interface complete with idl file?

Here is what I do, just in case...

For that, I never have been able to use the arx wizard, I use VS -> Add Class -> ATL Simple object -> fill the form with the class name -> under support select ISupportErrorInfo

Then, also the arx wizard (for me) does not work to add any new method, so I simple go to the idl file an under the IDispatch I place my method calls - manually (as I do also for my function calls too - the ones on my previous sample):

Code: [Select]
[id(1), helpstring("method GbPolySS")]
HRESULT GbPolySS([in] VARIANT ids, [in] BSTR LayerName, [in] BSTR LayerNameOut, [in] double dtol, [in] short poltip, [in] double areamin, [in] short inpol, [in] short outpol, [in] short dirpolhor, [out] VARIANT *objids);
[id(2), helpstring("method GbPolyPT")]
HRESULT GbPolyPT([in] VARIANT pt, [in] BSTR LayerName, [in] double dtol, [in] short poltip, [in] double areamin, [in] short dirpolhor, [out] LONG *objid);

I think that's it, (from memory).... :)

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Calling arx function from vb/a
« Reply #8 on: April 21, 2009, 04:35:56 PM »
Thanks Luis, I'll give that a go.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Calling arx function from vb/a
« Reply #9 on: April 21, 2009, 09:51:05 PM »
Thank you Gents, I got it working fine with an ATL object that I added after creating the project with COM enabled etc.
cheers,
Mick.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien