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

Retrieving boundaries from non-associative hatch

14 REPLIES 14
Reply
Message 1 of 15
jnelso99
930 Views, 14 Replies

Retrieving boundaries from non-associative hatch

Hello,

We're writing a VB.NET application to perform custom processing on AutoCAD files. The app reads in entities and performs various calculations on them. One of the tasks requires the boundaries from hatch objects, both associative and non-associative. Associative is fine (GetLoopAt function works), but the latter does not (GetLoopAt returns Nothing). I've seen the "HatchB" AutoLisp file floating around and will probably start poking around in that to see what's going on and if it will be of any help, but in the meantime, is there any possible way to get the boundary objects of a non-associative hatch entity via .NET? This is one of those "if it can't be done, the whole project is pretty much shot" kind of thing...

If any other details are needed, please let me know.

Thanks!
14 REPLIES 14
Message 2 of 15
jnelso99
in reply to: jnelso99

Hmm...looks like the only way is to call that Lisp function via a SendCommand call, but how would I get any usable data back to VB Land? Is there a way to populate a string (with the entity data the HatchB command parses) via the Lisp/SendCommand call, dump that string into a custom dictionary or xref or whatever, and have VB read it as a string for further parsing (basically doing whatever Hatchb does only in VB)?

Does any of this make sense, or am I just SOL and have to tell the customer that if they want this to work, they have to fix all of their DWG files?
Message 3 of 15
Anonymous
in reply to: jnelso99

have you tried using the hatches bounding box? Works in VBA, I haven't
tried in .net though.

wrote in message news:4909040@discussion.autodesk.com...
Hmm...looks like the only way is to call that Lisp function via a
SendCommand call, but how would I get any usable data back to VB Land? Is
there a way to populate a string (with the entity data the HatchB command
parses) via the Lisp/SendCommand call, dump that string into a custom
dictionary or xref or whatever, and have VB read it as a string for further
parsing (basically doing whatever Hatchb does only in VB)?

Does any of this make sense, or am I just SOL and have to tell the customer
that if they want this to work, they have to fix all of their DWG files?
Message 4 of 15
jnelso99
in reply to: jnelso99

I need to get the actual boundaries of the hatch, not just the extents. For some reason you're not allowed to do it the normal way with GetLoopAt if the hatch is non-associative. Thanks anyway.
Message 5 of 15
Anonymous
in reply to: jnelso99

the bounding box will point you toward the object
cant be to many in the same place
wrote in message news:4909197@discussion.autodesk.com...
I need to get the actual boundaries of the hatch, not just the extents. For
some reason you're not allowed to do it the normal way with GetLoopAt if the
hatch is non-associative. Thanks anyway.
Message 6 of 15
Anonymous
in reply to: jnelso99

>and have to tell the customer that if they want this to work, they have to
>fix all of their DWG files?

What if the customer had asked you to reassociate all hatches?

Find Bounding Box of hatch
Find Object whos' Bounding Box Matches
Copy properties of existingHatch, Create new one
Append object to your new hatch
Delete old hatch.

Might be an eaiser way, but I just tested this and it works fine.


wrote in message news:4909040@discussion.autodesk.com...
Hmm...looks like the only way is to call that Lisp function via a
SendCommand call, but how would I get any usable data back to VB Land? Is
there a way to populate a string (with the entity data the HatchB command
parses) via the Lisp/SendCommand call, dump that string into a custom
dictionary or xref or whatever, and have VB read it as a string for further
parsing (basically doing whatever Hatchb does only in VB)?

Does any of this make sense, or am I just SOL and have to tell the customer
that if they want this to work, they have to fix all of their DWG files?
Message 7 of 15
jnelso99
in reply to: jnelso99

Ah - now I see what you're saying. I'll give that a shot, but I'm not sure if it will work for all of my cases. There are some hatch entities that consist of multiple areas. For example, think of a dashed line drawn out where all of the dashes are included in a single hatch entity. Also, the hatch boundaries tend to consist of individual line segments (AcDbLine entities).

But as I think about it, I have an idea on how to make this work, at least good enough for government work 😉 I'm going to put this task aside for a day or two to regain my sanity before tackling it, tho.

I'd still like to know how to be able to call a Lisp function with SendCommand and get some kind of useful result data back to VB, just to satisfy my curiosity, but I think I'm set for now with my immediate problem. I really appreciate your help. Thanks!
Message 8 of 15
Anonymous
in reply to: jnelso99

>I'd still like to know how to be able to call a Lisp function with
>SendCommand and get some kind of >useful result data back to VB, just to
>satisfy my curiosity, but I think I'm set for now with my >immediate

How about the userr variables? I assume you can access these in .net

$USERI1 - 5 70 Five integer variables intended for use by third-party
developers
$USERR1 - 5 40 Five real variables intended for use by third-party
developers


wrote in message news:4909345@discussion.autodesk.com...
Ah - now I see what you're saying. I'll give that a shot, but I'm not sure
if it will work for all of my cases. There are some hatch entities that
consist of multiple areas. For example, think of a dashed line drawn out
where all of the dashes are included in a single hatch entity. Also, the
hatch boundaries tend to consist of individual line segments (AcDbLine
entities).

But as I think about it, I have an idea on how to make this work, at least
good enough for government work 😉 I'm going to put this task aside for a
day or two to regain my sanity before tackling it, tho.

I'd still like to know how to be able to call a Lisp function with
SendCommand and get some kind of useful result data back to VB, just to
satisfy my curiosity, but I think I'm set for now with my immediate problem.
I really appreciate your help. Thanks!
Message 9 of 15
Anonymous
in reply to: jnelso99

Have you considered upgrading to AutoCAD 2006 that has much better
functionality to restore boundaries than my HatchB.lsp?

--
Best Regards, Jimmy Bergmark
CAD and Database Developer Manager at www.pharmadule-emtunga.com
Blog: http://jtbworld.blogspot.com
JTB FlexReport (FLEXnet / FLEXlm report tool) -
http://www.jtbworld.com/jtbflexreport
SmartPurger (Purges automatically) -
http://www.jtbworld.com/?/smartpurger.htm
or download some freeware at http://www.jtbworld.com
More on AutoCAD 2005 and 2006
http://www.jtbworld.com/autocad2005.htm
http://www.jtbworld.com/autocad2006.htm


wrote in message news:4909345@discussion.autodesk.com...
Ah - now I see what you're saying. I'll give that a shot, but I'm not sure
if it will work for all of my cases. There are some hatch entities that
consist of multiple areas. For example, think of a dashed line drawn out
where all of the dashes are included in a single hatch entity. Also, the
hatch boundaries tend to consist of individual line segments (AcDbLine
entities).

But as I think about it, I have an idea on how to make this work, at least
good enough for government work 😉 I'm going to put this task aside for a
day or two to regain my sanity before tackling it, tho.

I'd still like to know how to be able to call a Lisp function with
SendCommand and get some kind of useful result data back to VB, just to
satisfy my curiosity, but I think I'm set for now with my immediate problem.
I really appreciate your help. Thanks!
Message 10 of 15
jnelso99
in reply to: jnelso99

That's what we're using. I haven't found how to get the boundaries through .NET, and everything I've seen on this group hints that it isn't possible withough jumping though lots of hoops. The documented "GetLoopAt" function doesn't seem to do as advertised with non-associative hatches. Most likely I'm doing something wrong, but I've only been working with this stuff for a week.
Message 11 of 15
Anonymous
in reply to: jnelso99

Have you tried using the command -HATCHEDIT and the options to restore the
boundary? It doesn't work on gradient hatches though.

--
Best Regards, Jimmy Bergmark
CAD and Database Developer Manager at www.pharmadule-emtunga.com
Blog: http://jtbworld.blogspot.com
JTB FlexReport (FLEXnet / FLEXlm report tool) -
http://www.jtbworld.com/jtbflexreport
SmartPurger (Purges automatically) -
http://www.jtbworld.com/?/smartpurger.htm
or download some freeware at http://www.jtbworld.com
More on AutoCAD 2005 and 2006
http://www.jtbworld.com/autocad2005.htm
http://www.jtbworld.com/autocad2006.htm


wrote in message news:4909511@discussion.autodesk.com...
That's what we're using. I haven't found how to get the boundaries through
.NET, and everything I've seen on this group hints that it isn't possible
withough jumping though lots of hoops. The documented "GetLoopAt" function
doesn't seem to do as advertised with non-associative hatches. Most likely
I'm doing something wrong, but I've only been working with this stuff for a
week.
Message 12 of 15
jnelso99
in reply to: jnelso99

I'll look into that command. One question, tho - Is there an automatic, non-interactive version of the command, so that a hatch entity would not need to be explicitly clicked by the user, and something like an object id can just be used instead? I would like this process invisible to the user. Thanks!
Message 13 of 15
Anonymous
in reply to: jnelso99

Using AutoLISP:
(command "-hatchedit" ent "B" "P" "Y")
where "ent" points to the object.
Not sure how to call this from .NET though.

--
Best Regards, Jimmy Bergmark
CAD and Database Developer Manager at www.pharmadule-emtunga.com
Blog: http://jtbworld.blogspot.com
JTB FlexReport (FLEXnet / FLEXlm report tool) -
http://www.jtbworld.com/jtbflexreport
SmartPurger (Purges automatically) -
http://www.jtbworld.com/?/smartpurger.htm
or download some freeware at http://www.jtbworld.com
More on AutoCAD 2005 and 2006
http://www.jtbworld.com/autocad2005.htm
http://www.jtbworld.com/autocad2006.htm


wrote in message news:4912895@discussion.autodesk.com...
I'll look into that command. One question, tho - Is there an automatic,
non-interactive version of the command, so that a hatch entity would not
need to be explicitly clicked by the user, and something like an object id
can just be used instead? I would like this process invisible to the user.
Thanks!
Message 14 of 15
jnelso99
in reply to: jnelso99

Excellent! I think it's going to work! I'm a happy camper! Thanks!

For whoever else needs it, here's more or less how to do this in VB.NET (minus error checking, type checking, imports, etc):

Public Sub ReassociateHatch(ByVal hatchid As Integer, ByVal acadDoc As AcadDocument)

Dim ent As AcadEntity = acadDoc.ObjectIdToObject(hatchid)
Dim cmd As String

cmd = "(command ""-hatchedit"" (handent """ & ent.Handle & """) ""B"" ""P"" ""Y"")" & vbCr
acadDoc.SendCommand(cmd)

End Sub
Message 15 of 15
jnelso99
in reply to: jnelso99

Ok, I may have spoken too soon about things working - wierd things are happening. I've basically got an MFC application calling a VB.NET library which calls AutoCAD. The VB.NET code does the SendCommand, and by default AutoCAD is set to be not visible (setting the AcadApplication.Visible to false). When my MFC app starts up, everything's ok, and I can load normal files with no problem. When I load one that requires the SendCommand("(command -""hatchedit""...) thing, when that SendCommand is called, the AutoCAD instance becomes visible and pops up. Not a problem - just reset the Visible flag on the AcadApplication again right after the SendCommand.

But what happens is when I load another file after that, I get an error and the AutoCAD instance goes away. The error message I get is "The object invoked has disconnected from its clients". I'm not getting them any more, but once there were message boxes saying exceptions occurred in "AcObjClassImp.arx" and "Acopm.arx".

The other wierd thing is that if I let the AutoCAD instance become visible, or start it off being visible, everything works fine. I'm wondering if there's some error or something that AutoCAD need to tell me about so it pops up.

I can put in code in my app to reconnect if it finds itself disconnected, but I'd rather figure out what I'm doing wrong here.

Edit: Also, the -hatchedit command does not seem to be able to handle hatch entities in block definitions. Bummer. Message was edited by: jnelso99

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