Author Topic: Can I pass an object to net from Vba  (Read 3188 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1883
Can I pass an object to net from Vba
« on: March 17, 2007, 03:25:17 PM »
I have a block with a leader that I would like to change scale with vba.
That is; scale the block then change the leader ScaleFactor , leaving the leader start in the same place.
(The block is a circle with 1 att and the leader is attached to either the left or right quadrant).
It appears I need to access Dxf 212- "Offset of last leader vertex from block reference insertion point"  and set this, which is a no go in vba. Looking at:
Code: [Select]
Public Overridable Property AnnotationOffset() As Autodesk.AutoCAD.Geometry.Vector3d
     Member of: Autodesk.AutoCAD.DatabaseServices.Leader
in net perhaps I can use this.
So can I pass an object and a double to Net?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Can I pass an object to net from Vba
« Reply #1 on: March 17, 2007, 06:51:54 PM »
Bryco, you can write functions in .NET that accept and return parameters from/to lisp, but I have no idea about from/to VBA.

Writing a COM interface is a solution that comes to mind.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Can I pass an object to net from Vba
« Reply #2 on: March 17, 2007, 07:15:22 PM »
Thanks Kerry,I'll keep looking.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Can I pass an object to net from Vba
« Reply #3 on: March 18, 2007, 02:34:12 AM »
You should be able to write an exposed class that allows you to pass objects and other parameters just like you do any other program. For example, as is done in this code:
Code: [Select]
Option Strict Off
Option Explicit On
<System.Runtime.InteropServices.ProgId("InterfaceObject_NET.InterfaceObject")> Public Class InterfaceObject
Private objActiveBlock As Object
Private dblLdrScale As Double

Public Property ActiveBlock() As Object
Get
ActiveBlock = objActiveBlock
End Get
Set(ByVal BlockRef As Object)
objActiveBlock = BlockRef
End Set
End Property

Public Property LeaderScale() As Double
Get
LeaderScale = dblLdrScale
End Get
Set(ByVal LdrScale As Double)
dblLdrScale = LdrScale
End Set
End Property

Now in VBA you will reference the .NET dll as an object library, then simply set the properties like you would in any other VBA program ...

i.e.
Code: [Select]
InterfaceObject.LeaderScale = xxxxx
InterfaceObject.ActiveBlock = ThisDrawing.Blocks.Item(X)

Now for the disclaimer ..I have not tested the above code and as a result it may contain bugs. Testing the code will be your job .. let me know if it works out ok
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Can I pass an object to net from Vba
« Reply #4 on: March 18, 2007, 11:53:24 AM »
That looks good mate.
Might be a while before I get the hang of it.
I've just finished looking at the net video and am clonking around a bit.
So far I feel about as sharp as a bowling ball with the net stuff.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Can I pass an object to net from Vba
« Reply #5 on: March 18, 2007, 01:57:23 PM »
Having a bit of bother adding the reference.
I presume you mean the references in the vbaide->Tools->References.
From reading a bit the .net dlls are not at all like the vb.dlls so I need to make a .tlb using "Register for Com Interop True". This option doesn't appear to come with the free version.
But under right-click the project in solution explorer->Application->Assembly information one can check "Make assembly Com-Visible"
I didn't appear to create a tbl when rebuilding so on looking at help, "regsvcs /appname:myTargetApp myTest.dll" which I think is asking you to add the appropriate line in Debug-> "Command line arguments " It doesn't seem to work either so far.


Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Can I pass an object to net from Vba
« Reply #6 on: March 18, 2007, 08:04:52 PM »
have you tried registering the dll?

regsvr32 C:\pathtodll\mydll.dll

If need be you can actually build a class dll in VB2005 Express and import that into both your VBA program and your .NET program, but for all intents and purposes, I believe the dll does need to be built with com visible.

Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Can I pass an object to net from Vba
« Reply #7 on: March 18, 2007, 09:06:29 PM »
It doesn't seem to want to register, rather gives this error message  "Can't find module"  and net doesnt have modules (maybe)