Linking / Associating Standard AutoCAD Entities (.NET)

Linking / Associating Standard AutoCAD Entities (.NET)

Lawrence_Viaud
Participant Participant
598 Views
9 Replies
Message 1 of 10

Linking / Associating Standard AutoCAD Entities (.NET)

Lawrence_Viaud
Participant
Participant

I’m looking for some coding feedback on building an internal reusable AutoCAD .NET library that allows standard AutoCAD entities (i.e. blocks, circles, polylines, ellipses, solids, etc.) to remain logically associated with other geometry (such as curves or regions (closed polylines)) without having to use custom entities. The idea is to store persistent relationship data in the drawing and recompute object placement when either the reference geometry or the dependent object changes (so, it stays even if drawing is closed/reopened). User edits should be interpreted as parameter changes or overrides rather than breaking the association. I’m especially interested in whether this “relationship and recompute” approach is a good approach and possible limitations.  I'm more so looking for what would be considered the best practice to accomplish something like this using the .NET api.

These are some super basic examples of what I was thinking:

Lawrence_Viaud_0-1770221328727.png

Lawrence_Viaud_1-1770221350623.png

Thanks,

 

 

0 Likes
Accepted solutions (1)
599 Views
9 Replies
Replies (9)
Message 2 of 10

_gile
Consultant
Consultant

Hi,

Based on your description and the photos, I would say: blocks (or groups).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 10

Lawrence_Viaud
Participant
Participant

Thanks for the reply.

Even though I have pretty simple example shown the goal is ultimately to create a larger program that is able to place what will most likely be blocks or Multiview blocks along an alignment. But I want the positions/stations of the objects to persist even if the alignment changes or moves. Also, want this behavior to remain even if cad is closed. So, if I have "alignment a" and "objects b and c" are linked to "alignment a". I would like "alignment a" to be aware of this linking and any changes made to "alignment a" will affect the positions of "objects b and c". Is there a way in the api to establish a relationship like this? 

Also, I say alignment, but it can be used pretty interchangeably with a regular AutoCAD line/polyline. 

0 Likes
Message 5 of 10

Lawrence_Viaud
Participant
Participant

Thanks, this should be what I was looking for.

Message 6 of 10

ActivistInvestor
Mentor
Mentor

If you want the most-robust way to accomplish your objectectives, that would be by using the associative framework. It's purpose is to address the precise type of problem you want to solve.

 

To understand what it does and how it works, see this overview (Gemini).

 

You can find example .NET code by looking through the results of this discussion group search.

 

Caveat Emptor: The associative framework and API is not for the faint-hearted. It's one of the most complicated aspects of both native and managed AutoCAD development, and requires a fairly good understanding of AutoCAD and its database.

0 Likes
Message 7 of 10

JamesMaeding
Advisor
Advisor

@ActivistInvestor 

Very interesting, I had not seen that. I would have to soak that in for a while, looking through examples.

For OP, this subject is something I have dealt with a lot, with the goal being no custom entities.

You basically track entities by handles, but those change easily (wblock...) so then you want some way to rediscover the group.

You can tag things by xdata to help, like a random number that could possibly repeat, but unlikely to mess up that rediscover process.

TT likely laughs at this, its herding cats, I know.

It can be done on limited basis, and I bet chatgpt could get you pretty far, as its good at writing what I call "house keeping" subroutines.

Depends how complex you want to get.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 8 of 10

Lawrence_Viaud
Participant
Participant

Can't believe I'm just now seeing this. But thank you for the insight. I'm not an expert on the AutoCAD API by any means, but it is interesting to see that something I was already thinking about already exists. I'm sort of a cheat when it comes to the API. I've been using AutoCAD Codepack for all of the projects I work on, as it is significantly easier for me. So like James Maeding was saying, I may need AI to get me started on this. I'm wondering how these two systems, between overrule and the associative framework, work. I continued the thread you gave me on Gemini, and it looks like the associative framework would be used first to establish the permanent linking of the objects, and the overrules would control the display at runtime, ensuring if object A is moved, then object B moves with it (associative framework), and if someone tries to move object B by itself, it either moves object A or puts it back in the correct associative spot (overrule). Super cool!

0 Likes
Message 9 of 10

Lawrence_Viaud
Participant
Participant

Thank you for the input

0 Likes
Message 10 of 10

ActivistInvestor
Mentor
Mentor

No, overrules are really not required for the kind of associativity that you envision. The associative framework takes care of everything including the persistent linking, and calling the code that you provide to update one or more dependent objects when the object they are dependent on is modified. It also handles cyclical references so that when a modified  object triggers an action, that object cannot be modified again as part of the reaction. 

0 Likes