Author Topic: How to create Link between objects?  (Read 2126 times)

0 Members and 1 Guest are viewing this topic.

Augusto

  • Newt
  • Posts: 75
How to create Link between objects?
« on: June 01, 2023, 10:18:08 PM »
Hello, everyone!

I decided to step out of my comfort zone and put autoLisp aside for a while. This is my first code in C# for AutoCAD.

The goal of this code is to initially create a representation of a flexible tube. I would really like to link the block I'm creating with the polyline and, depending on the event, recreate the block while maintaining its initial creation characteristics.

Unfortunately, after many attempts, I couldn't store the block information within the polyline. In the commented sections of the code, I can create a dictionary and assign it to the polyline, but after the modification (stretch), the dictionary disappears, and I can't access it to obtain the ObjectId of the block and then perform the deletion.

Since I don't have previous experience with the API, I imagine my code is not very good, and I'm also not following any best practices in AutoCAD .NET development, which results in duplicated code and other oddities. In the future, I will strive to produce something better, but for now, I'm just trying to learn and make it work.

I would greatly appreciate it if you could assist me with object linking and perhaps provide tips on best practices in AutoCAD .NET development.

I'm using autoCAD 2020 and visual studio 2019.

I've been looking at some code on the through-the-interface page. This would be the best scenario, where the links are maintained and loaded when loading the drawing, but I think I'm not ready to implement something of such complexity yet.

https://through-the-interface.typepad.com/through_the_interface/2006/11/linking_circles_1.html

I haven't worked with the collisions and other things that must be done yet, so the code produces bad results on very steep curves. I intend to put the minimum bend radius based on the diameter and material properties.

The project is attached, as well as the dwg file in 2010 format.

Thanks in advance for any help.

Best regards, Luís Augusto.

Hanauer

  • Mosquito
  • Posts: 10
Re: How to create Link between objects?
« Reply #1 on: June 02, 2023, 07:26:53 AM »
Surely there are people with more experience than me to answer. What I am going to expose here may not be completely correct as it is based on my experience and I hope someone corrects what is wrong.
I just have an app that makes use of something similar that you're aiming for and I haven't touched it in a while.
As the subject is vast I think it is difficult to get solutions right away. At least in my case, I adjusted it little by little and it took a long time for it to work properly.
Have a look at Deep Clone, HardPointerId, SoftPointerId, DBDictionary.TreatElementsAsHard, ObjectOverrule.
When you copy a "FlexTube" (within the same file or between files) you want it to have the same properties as the original.
If you look closely at Kean's example he uses DxfCode.SoftPointerId. From what I saw you are using DxfCode.Text.
There are differences between the usage of HardPointerId and SoftPointerId.
For "FlexTube" modifications I would implement this in entirely separate code via ObjectOverrule.
There is a content called AU2010 - CP230-1V - AutoCAD® .NET - Practical Examples of Customizing AutoCAD Entity Behavior from Autodesk University 2010 written in VB .NET by Stephen Preston which I think can help because it has examples that you can practice, of course it involves time.
« Last Edit: June 02, 2023, 08:07:38 AM by Hanauer »

57gmc

  • Bull Frog
  • Posts: 365
Re: How to create Link between objects?
« Reply #2 on: June 02, 2023, 11:04:55 AM »
I'm wondering if you can do this with constraints. I haven't used constraints in AutoCAD much, but in Inventor, you can make it flexible with angular constraints.

Augusto

  • Newt
  • Posts: 75
Re: How to create Link between objects?
« Reply #3 on: June 02, 2023, 01:30:02 PM »
Hanauer, Thank you for your reply and valuable information!

As the subject is vast I think it is difficult to get solutions right away. At least in my case, I adjusted it little by little and it took a long time for it to work properly.

I believe I have a long road ahead of me, and maybe I have to walk the same path as yours.

Have a look at Deep Clone, HardPointerId, SoftPointerId, DBDictionary.TreatElementsAsHard, ObjectOverrule.

I will definitely follow your advice and study concepts like Deep Clone, HardPointerId, SoftPointerId and DBDictionary.TreatElementsAsHard. I was initially hesitant to use ObjectOverrule as I had read about it some time ago and had a hard time understanding how it works.

When you copy a "FlexTube" (within the same file or between files) you want it to have the same properties as the original.

It seems to me the most correct. But I still have no idea how to do that. Maybe I have to create my own object cloning method.

If you look closely at Kean's example he uses DxfCode.SoftPointerId. From what I saw you are using DxfCode.Text.
There are differences between the usage of HardPointerId and SoftPointerId.

I guess I didn't pay much attention. Thank you for guiding me around this.

There is a content called AU2010 - CP230-1V - AutoCAD® .NET - Practical Examples of Customizing AutoCAD Entity Behavior from Autodesk University 2010 written in VB .NET by Stephen Preston which I think can help because it has examples that you can practice, of course it involves time.

I'll check out the feature you mentioned, AU2010 - CP230-1V - AutoCAD® .NET - Practical AutoCAD Entity Behavior Customization Examples by Stephen Preston in VB .NET. It looks like a valuable reference that will provide me with practical examples to work with.

Thanks again for your guidance and for pointing me in the right direction. I really appreciate your willingness to share your knowledge. I will actively explore and test the examples you mentioned to further enhance my understanding.

Best regards, Luís Augusto.

Augusto

  • Newt
  • Posts: 75
Re: How to create Link between objects?
« Reply #4 on: June 02, 2023, 01:37:02 PM »
I'm wondering if you can do this with constraints. I haven't used constraints in AutoCAD much, but in Inventor, you can make it flexible with angular constraints.

Thank you for your reply, 57gmc.

In the future I will try to use constrains to make the connection between the paths that the tubes must follow.
I'll try to solve getting information between objects first. I know that it is also possible to do this using Xdata, but I also have doubts whether this will be good for the future of the project.

57gmc

  • Bull Frog
  • Posts: 365
Re: How to create Link between objects?
« Reply #5 on: June 02, 2023, 02:51:53 PM »
I'm wondering if you can do this with constraints. I haven't used constraints in AutoCAD much, but in Inventor, you can make it flexible with angular constraints.

Thank you for your reply, 57gmc.

In the future I will try to use constrains to make the connection between the paths that the tubes must follow.
I'll try to solve getting information between objects first. I know that it is also possible to do this using Xdata, but I also have doubts whether this will be good for the future of the project.
I was suggesting that you could do it with constraints alone, no programming and no extra data. If you can figure out how to use constraints, you could write some code to automate the placement of constraints.

Augusto

  • Newt
  • Posts: 75
Re: How to create Link between objects?
« Reply #6 on: June 02, 2023, 03:43:00 PM »
I was suggesting that you could do it with constraints alone, no programming and no extra data. If you can figure out how to use constraints, you could write some code to automate the placement of constraints.

Yes, I understand your suggestion. I've even used this approach in a lisp code.

To keep the block bound to the path yes would work, but it turns out that in the future I plan to do things like bend the tube using the polyline path. When that happens I will have to update the representation of the tube shape.

In the current code, I couldn't do the basics which would be to delete the representation and create a new one when updating the line length.  :rolleyes2:

Another question I have is whether other CAD software would have access to such a feature. (constraints)

Anyway thanks for your contribution.

57gmc

  • Bull Frog
  • Posts: 365
Re: How to create Link between objects?
« Reply #7 on: June 02, 2023, 03:58:43 PM »
Yes, my preference would be Inventor. It does solid modeling very well. You could use a spline for the centerline to constrain to. When you change the shape of the spline, all the segments would adjust. You could also control the length of the tube by a parameter that sets the number of segments in the tube. I haven't tried it, but I think it would work. You could probably do it in AutoCAD too. Edit: I just checked AutoCAD's constraints again and they don't have the ability to be flexible like Inventor, e.g. Inventor angle constraint can be a range like 0-10.
« Last Edit: June 02, 2023, 04:23:32 PM by 57gmc »

Augusto

  • Newt
  • Posts: 75
Re: How to create Link between objects?
« Reply #8 on: June 05, 2023, 12:07:34 PM »
I need to make a correction, actually.  :oops:

The code shared by Kean Walmsley was meticulously organized and I can easily adapt it for my purposes. I only made a few adjustments to the UpdateLinkedEntities method to align with my specific requirements. method to work with the entities as per my need.

Thank you so much for those who were willing to help me.