Custom Subassemblies

Custom Subassemblies

ryarmak
Advocate Advocate
1,794 Views
14 Replies
Message 1 of 15

Custom Subassemblies

ryarmak
Advocate
Advocate

Hello

 

I'm looking into figuring out custom subassembly programming, but I have a question that I've not had much luck figuring out the answer for searching on my own (largely due to the failings of the search feature of this forum)

 

Is it possible to program subassemblies in C#?  I have a C++/Java background, and I would rather use a language that is similar to what I already know than having to look into visual basic.  All the example files for custom subassemblies are in VB.net so I don't think it would be terribly difficult to just use them as a base, but I just feel more comfortable in the land of braces and semicolons.  I know, crazy eh? 

 

I am just starting to get into .NET programming for AutoCAD, largely because my working environment has a huge lisp library to utilize so COM just ended up an easier (and I have gotten to the point where LISP is my most proficient language).  I guess if I was more familiar with .NET programming for AutoCAD, I probably would be able to answer my own question. 

 

Thanks in advance.

 

BTW, Its hard to search for C# on these forums because # is ignored by the parser.  Argh.

0 Likes
1,795 Views
14 Replies
Replies (14)
Message 2 of 15

Jeff_M
Consultant
Consultant

Yes, C# can be used just fine. The biggest drawback is, as you noted, that all the Subassembly examples are in VB.NET. 

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 15

ryarmak
Advocate
Advocate

Alright.  Thank you much.. I'll see what I can figure out then. 

0 Likes
Message 4 of 15

klugb
Advisor
Advisor

Check this out. I have been able to create subassemblies with ease.

 

http://labs.autodesk.com/utilities/civil3d_subassembly_editor/

 

Bruce

Bruce Klug, P.E.
AutoCAD Expert Elite Alumni
AutoCAD Civil 3D Certified Professional
Civil 3D 2023.2.1

Win 10 Enterprise, 64-bit
0 Likes
Message 5 of 15

ryarmak
Advocate
Advocate

Well, going through tests with the subassembly composer, i found that it cannot make what we need.  There is no way to actually use offset/elevation target parameters, which I need. 

 

So I have been attempting to make a C# version of the base subassembly files that come with Civil3d, and have hit a snag with certain objects not being able to be cast properly even though the docs say that it should.  It seems Point3d cannot be cast to ParamPoint, and ParamPointCollection.Value(string) is returning a Point3d rather than a ParamPoint as the documentation states it should return.  It seems that using Add() rather than Value() will give me what I want, but it just seems odd to have to use an input method as a get method.  Somewhat frustrating, but if it works, it works.

 

I guess I will keep trudging along.  If anyone knows if the Subassembly Composer will eventually be updated for Target Parameters to work properly rather than just for surfaces, that would be great, then I wouldn't have to go through this mess. 

 

 

0 Likes
Message 6 of 15

dnl999
Advocate
Advocate

But there are several subasemblies including generic subassemblies which can target offset/elevation.

Why don't you use them ?

0 Likes
Message 7 of 15

ryarmak
Advocate
Advocate

I will look into seeing if there are existing subassemblies to do the job for me, but it hasnt been looking good.  Divided highways with a single centerline seem to be a big pain.  I am coming from an LDD background up to this point (our first civil 3d project here is a doozy), so I am used to just being able to draw exactly what we need, set a few points, attach a few alignments/profiles, and suddenly it works the way we need it for quantities.  I am frustrated that this is *NOT* how it works in civil 3d. 

 

From a programming background more than a manual drafting background, I tend to just program my way out of tight spots, which is why I went straight for custom subassemblies rather than frustratingly trying to sift through all of the existing stuff to hack something together than may work.

0 Likes
Message 8 of 15

ryarmak
Advocate
Advocate

As it turns out, you cannot do subassemblies in C#.

 

I just rewrote a single subassembly (that I need a new version of, because the existing one is backwards in the way it uses attached slopes) in C#, along with all the helper functions.  In large part, it wasn't that bad, seeing that its really my first time using a .net language, the rewrite helped me get my bearings. 

 

The one problem is, ParamPointCollection was not implemented in a way that you can access in C#. 

 

In VB.Net, this is the code to grab a marked point from the collection:

 

oParamPoint = oParamsPoint.Item(vMarkedPointName)

 Which I believe should have this as a C# equivalent:

 

 

oParamPoint = oParamsPoint[vMarkedPointName];

 Visual Studio auto-fill-in has an option for this, but as soon as it is finished typing, the autocompiler gives an error that type ParamPointCollection is unable to have the [] operator on it.  ParamPointCollection.Value(string index) returns a Point3d, which does not cast to ParamPoint in any reasonable way (and it gives basically no information either).

 

I mostly wanted to get this up there, so maybe someone will see it that may be able to get it put on a bug list or something... I will attempt to do what I need in vb.net, but kicking and screaming.  Luckily the only thing I really need is to change some variables sign to negative. 

 

0 Likes
Message 9 of 15

Jeff_M
Consultant
Consultant

Would you be willing to post your code? Someone here may be able to suggest something other than VB Smiley Happy

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 10 of 15

ryarmak
Advocate
Advocate

Sure. 

This is basically the rewrite of the helper functions and one of the autodesk standard subassemblies.  I'm not sure about any code that deals with the [type]ParamCollections, as I think thats where things started to fall apart.   But it compiled, and loaded into Civil3d.  I bet if I wasn't trying to connect to a marked point, it would have worked.  

 

There are some bits that I know I would rewrite if I could get it to work in the first place, my personal coding style stems very much from my extensive lisp background so I really can't help but want to put a lot of small helper methods in whenever I have to write something more than twice (restrained myself when doing this test, only put in one extra method from before).

 

I did get this subassembly to work properly using vb.net, seeing that I only had to swap the signs for the slope inputs to get what we needed.  I am designing a truely custom subassembly right now, lots of prep work I am finding, very interesting!

 

If anyone figures this out, please share it back... I really really want to use C# rather than VB... I like my {}; and != ==. 

 

Always, thanks for the help I've gotten on here!

Message 11 of 15

Jeff_M
Consultant
Consultant

Well, not sure what's up with this, but C3D forces the name in the PointsParamCollection to upper case.

 

Changing this line:

oParamPoint = oParamsPoint[vMarkedPointName];

 

to this:

oParamPoint = oParamsPoint[vMarkedPointName.ToUpper()];

 

allows the code to complete. Although the results aren't what I'd expect...I didn't check the rest of the code, as that wasn't your question/comment of concern. I'm sure you'll get that part figured out now that it can run without error.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 12 of 15

ryarmak
Advocate
Advocate

Really? I must be missing something because when I have oParamsPoint[vMarkedPointName.ToUpper()] it still gives me:

 

Cannot apply indexing with [] to an expression of type 'Autodesk.Civil.Runtime.ParamPointCollection'

 

Something must be off with me if you're able to get it to work.

 

 

0 Likes
Message 13 of 15

Jeff_M
Consultant
Consultant

Just a thought....Are you using the 64-bit version of C3D2011? Do you have Service Pack 1 installed for C3D2011? 

 

From the Readme for the SP: An issue with certain API methods using an incorrect array type has been resolved for 64-bit operating systems.

 

 

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 14 of 15

ryarmak
Advocate
Advocate

I am using the 64 bit version, but according to the Update 1 installer, I already have it installed.  It does sound like my problem I am having from the update notes.  Maybe I should send a bug report through the subscription center. 

0 Likes
Message 15 of 15

ryarmak
Advocate
Advocate

Just wanted to update now that I got the C# version of subassemblies to compile.  The only point on my subassembly that was right, was the point I couldn't get to work (marked point), the rest of everything I think the math is wonky, but it compiles, and it loads visually into the drawing.  This is a big plus!

 

Thanks for all the help in this endeavour, I probably will end up with more questions, but probably not weird error type like I have been having.

 

0 Likes