Hatch (Addhatch method) without using Autocad reference in VB.NET

Hatch (Addhatch method) without using Autocad reference in VB.NET

ahmad_a1054
Explorer Explorer
558 Views
5 Replies
Message 1 of 6

Hatch (Addhatch method) without using Autocad reference in VB.NET

ahmad_a1054
Explorer
Explorer

Hi. I want to draw Hatch using ADDHATCH method without importing any Autocad reference. I tried this method before in VBA (VB6). It didn't work in VB.NET. 

The sample code is this:

 

      ' Defining hatch object as "Object" (instead of "AcadHatch") should prevent the code from requiring AutoCAD references.

        ' (It is working for other functions --> using "As Object" instead of "As AcadCircle" or "As AcadLWPolyline" or ...)

        ' But an error is risen when hatch is defined "As Object".

        

Dim hatchObj As Object

        hatchObj = acaddoc.ModelSpace.AddHatch(1, "SOLID", True)

        ' Create the outer boundary for the hatch. (a circle)

        Dim CircleCenter(2) As Double

        CircleCenter(0) = 0 : CircleCenter(1) = 0 : CircleCenter(2) = 0

        Dim CircleRadius As Double = 20

        Dim outerLoop(0 To 0) As Object

        outerLoop(0) = acaddoc.ModelSpace.AddCircle(CircleCenter, CircleRadius)

        ' !!! Error appears in the following line !!!

        hatchObj.AppendOuterLoop(outerLoop)

        hatchObj.Evaluate

0 Likes
559 Views
5 Replies
Replies (5)
Message 2 of 6

Ed__Jobe
Mentor
Mentor

By definition, VBA can only run in the host application's thread. Therefore, VBA assumes you will need the host's api and automatically references it for you. So, it's unnecessary to try to use Object instead. You might as well dim it as AcadHatch and benefit from Intellisense.

 

You didn't really ask any question. Are you having a problem? If you get an error, always state what the error is and the context of the error, e.g. what line threw the error in debug mode.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 6

ahmad_a1054
Explorer
Explorer

thanks for reply.

I mentioned the error in the code:

"error appears in the following line"

 

the problem is that "appendOuterLoop" does not work, because I didn't import the Autocad references (this is a trick to make the program independent from installed Autocad version).

as I didn't import any dll file, I can't write "acadhatch" because it is not known for program. 

the main problem is AppendOuterLoop command.

0 Likes
Message 4 of 6

Ed__Jobe
Mentor
Mentor

Are you running VBA or trying to run code from another app, like Excel. If you are using vba, then as I said before, its useless to try to not reference a type library.

 

What does the actual error say? type mismatch? or something else?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 6

ahmad_a1054
Explorer
Explorer
thanks for reply.

about reference: defining acad related items AS OBJECT free the program
from adding any dll file. the benefit is that the exe file could work with
different versions of Autocad and there is no need to add reference for
each version of Autocad (for different PCs).

I'm trying to create an exe file with vb.net. the error appears in the
following line:

hatchObj.AppendOuterLoop(outerLoop)

Err: Invalid object array

I found out that the problem is defining hatch object AS OBJECT instead of
AcadHatch. when acad reference was added, type "acadhatch" became enabled.
this new definition removed the error.

my big question is that is there a way to draw hatch with AddHatch method
without adding autocad reference?
0 Likes
Message 6 of 6

Ed__Jobe
Mentor
Mentor

Ok, since you are using .NET, you can use the DYNAMIC keyword instead of late binding. See this post.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes