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

Utility Classes - A Start

25 REPLIES 25
Reply
Message 1 of 26
sunburned.surveyor
751 Views, 25 Replies

Utility Classes - A Start

I was thinking about a form I am currently designing for a dialog that will allow the user to label coordinates in Model Space. I was thinking in particular about some controls that could probably take advantage of common code wrapped into a GUIHelper class.

I wanted to ask if someone might share the following code with me, if it is available.

[1] I need to fill a ListBox with all of the layers that exist in a drawing. I was thinking we could create a method that accepts a ListBox as an argument and then fills it with the existing Layers. If someone can share with me their code for accessing a list of existing layers in a drawing I will write the rest of the method and stick it in the GUIHelper class.

[2] I'm not sure how convoluted the logic is to display the Layer Dialog Box. If involves more that one or two method calls I thought we could wrap this in another method of the GUIHelper class. This will allow the button to show the dialog with a single call like helper.showLayerDialog(). Can anyone share with me the code needed to open the LayerDialog?

[3] I'll need to come up with a dialog that allows the configuration of MText entities that are created by some of my tools. (For example, the text containing the coordinate values of a selected point for my current tool.) I was wondering if we could come up with a standard dialog box and supporting classes that can be used for this purpose. If I design the code for this will someone review it and comment?

P.S. - I have set up a spot in my SVN repository at the SurveyOS SourceForge Project for my AutoCAD .NET code. I will release it under the GPL. As soon as I have some time I will post a link to the Project website, the repository, and instructions on how to contribute. I welcome other developers that would like to collaborate and share code to contact me about placing a module on the SVN.

Scott Huey Message was edited by: Sunburned Surveyor
25 REPLIES 25
Message 2 of 26

This might work for your purposes. I also have my own utility classes with plenty of code in them for common purposes (the most often used by me are different kinds of selection, adding entities to the database, working with blocks and attributes, getting input from the user, and transformations) so if there's a project to get a well formed library I'll be happy to contribute. It's all in VB by the way.

Dim lstLayerNames As New List(Of String)
Dim acadDB As Database = HostApplicationServices.WorkingDatabase
Dim acadTrans As Transaction = acadDB.TransactionManager.StartTransaction
Dim ltLayerTable As LayerTable = CType(acadTrans.GetObject(acadDB.LayerTableId, OpenMode.ForRead), LayerTable)
Dim ltrLayerRecord As LayerTableRecord

For Each id As ObjectId In ltLayerTable
ltrLayerRecord = CType(acadTrans.GetObject(id, OpenMode.ForRead), LayerTableRecord)
lstLayerNames.Add(ltrLayerRecord.Name)
Next

acadTrans.Commit()
acadTrans.Dispose()
acadDB.Dispose()

Return lstLayerNames
Message 3 of 26
Anonymous
in reply to: sunburned.surveyor

>> I was wondering if we could come up with a standard dialog box and supporting classes that can be used for this purpose <<

It seems like you're asking the entire group to
write a real software application for you.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
Message 4 of 26
Anonymous
in reply to: sunburned.surveyor

>> acadDB.Dispose()

You might want to browse this newsgroup and
read some of the posts dealing with the subject
of disposing of things like databases that you
didn't create.

There's no harm in doing it because the managed
runtime is smart enough to catch the mistake,
and not allow it to do any damage. However, that
doesn't make it any less of a mistake.

There's a lot of confusion about what you are,
and are not suposed to dispose of, so the mstake
is fairly common and that's what seems to lead
others to believe its the right way to do things.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5639010@discussion.autodesk.com...
This might work for your purposes. I also have my own utility classes with plenty of code in them for common purposes (the most often used by me are different kinds of selection, adding entities to the database, working with blocks and attributes, getting input from the user, and transformations) so if there's a project to get a well formed library I'll be happy to contribute. It's all in VB by the way.

Dim lstLayerNames As New List(Of String)
Dim acadDB As Database = HostApplicationServices.WorkingDatabase
Dim acadTrans As Transaction = acadDB.TransactionManager.StartTransaction
Dim ltLayerTable As LayerTable = CType(acadTrans.GetObject(acadDB.LayerTableId, OpenMode.ForRead), LayerTable)
Dim ltrLayerRecord As LayerTableRecord

For Each id As ObjectId In ltLayerTable
ltrLayerRecord = CType(acadTrans.GetObject(id, OpenMode.ForRead), LayerTableRecord)
lstLayerNames.Add(ltrLayerRecord.Name)
Next

acadTrans.Commit()
acadTrans.Dispose()
acadDB.Dispose()

Return lstLayerNames
Message 5 of 26

Tony,

Thanks for the warning in your previous message on this thread.

You wrote: "It seems like you're asking the entire group to
write a real software application for you."

I'm not asking anybody to write any of my code, so I apologize if I gave the wrong impression. I'm an open source developer and I prefer to share ideas and code when I can. I realize that this might be a foriegn idea to some people that are developing with AutoCAD software, but they will get used to it.

I've already started work on the text configuration dialog box and will make the code available for review and comments. I hope to do this later in the week when all of the DotNET code I have been working on for AutoCAD gets posted online.

I'm trying to set something up that is similar to the Apache Jakarta Commons project.

http://jakarta.apache.org/commons/

It will basically be a shared library of "utility" code that makes customization of AutoCAD using DotNET a lot easier for everyone. There is no need to write the same basic routines and logic over and over. We can share it with one another. If we take a professional approach to this we may even see some of our code adopted by Autodesk. They seem to be more open to open source development than they were in the past.

Scott Huey Message was edited by: Sunburned Surveyor
Message 6 of 26
Anonymous
in reply to: sunburned.surveyor

>> I realize that this might be a foriegn idea to some
>> people that are developing with AutoCAD software,
>> but they will get used to it.

Doubt it.

Most people who are developing with AutoCAD are
not in the position to share what they produce,
because they are paid to produce the code the write,
which usually means the party that signs the check
is the owner of the work. Hence, the person paid to
produce it generally doesn't have any legal right to
share it with anyone.

Out of curiosity, what have you contributed to the
open source community?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
Message 7 of 26

Tony,

It seems like you lack confidence in the viral nature of open source software design. I think that it may surprise you.

Tony wrote: "Most people who are developing with AutoCAD are
not in the position to share what they produce,
because they are paid to produce the code the write,
which usually means the party that signs the check
is the owner of the work. Hence, the person paid to
produce it generally doesn't have any legal right to
share it with anyone."

I don't think getting paid to write code is really an obstacle in most cases. There are a great deal of people who are professional programmers contributing to open source projects. Oftentimes this is done as part of their employment. On one of the open source projects I work on only 2 or 3 members of the development team are volunteers. Everyone else contributes to the program on someone's payroll.

Besides, I think there are probably a lot of guys like me that are just out to add a little functionality or to make a little tweak.

Tony wrote: "Out of curiosity, what have you contributed to the
open source community?"

Do you doubt my qualifications, or do you question my motives?

I'll humor you since I'm new to this list and I'd like to be polite. I serve as one of the project administrators and developers for the JUMP Pilot Project. The JPP produces and maintians OpenJUMP, an open source GIS program written in Java. I've been known to dabble in other open source projects, but OpenJUMP is the only thing I dedicate serious time to.

If you would like to learn more you can take a look at my OpenJUMP blog:

http://openjump.blogspot.com/
Message 8 of 26
Anonymous
in reply to: sunburned.surveyor

Scott,

Welcome aboard.

I'm not trying to speak for Tony, but I think his post could be summarized
as "show me the money". I don't doubt that you have a lot of experience
with open source projects in some capacity, but you strike me (and obviously
Tony) as a non-programmer. You obviously have an agenda to promote open
source. Usually, this combination of traits indicates a person that
consumes open source projects instead of creating them. To old and cranky
programmers like Tony, you look like another case of a wanna-be programmer
trying to get real programmers to do the job for him. 🙂
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com
Message 9 of 26

Owen,

Thanks for the clarification. I think my mistake was asking for contributions before throwing up my own code. I will admit that I am just starting with C# and .NET development, but I hve been programming for several years, and I am much more a producer of code than a consumer of one. My main language is Java, but I've also dabbled in AutoLISP, new LISP, Python, Visual Basic, and some C. One of my favorite projects was writing an XML pull parser in Java, from scratch.

I don't doubt that my expertise in the AutoCAD .NET API and .NET programming will be limited, but I'm not sure why I gave you and Tony the impression that I was a button pushing code-ignorant idiot. Maybe you guys are indeed just old and cranky. :]

I was just surprised at detecting what seemed to be a little hostility Tony's responses. In the end, the proof is in the pudding. If, after taking a look at some of my code, you think I'm an idiot looking for others to paint my picket fence, you don't have to contribute or even answer my posts.

Its also important to remember that you don't have to contribute anything to the library that I am trying to put together if you don't want to. In fact, you can use all of the code there and never contribute a thing if you want.

Thanks again for tamping down the fire. I hope I haven't offended Tony. :]

P.S. - I have put my first source code files for AutoCAD .NET development on the SurveyOS SourceForge Subversion Repository. This code isn't really utilit code, but is for a little tool that I am writing which will label coordinates. You can look at the files here:

http://surveyos.svn.sourceforge.net/viewvc/surveyos/c_sharp/AutoCAD/Commons/Annotations/LabelCoordinate/

I will post another message with instructions on how to access the code. Message was edited by: Sunburned Surveyor
Message 10 of 26
Anonymous
in reply to: sunburned.surveyor

> I hope I haven't offended Tony. :]

There aren't many people posting here that haven't offended Tony. Just
consider it an initiation rite. 🙂
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com
Message 11 of 26

Hi Tony, I'm very interested in your comment. Is there any post or article in particular that can help me avoid these mistakes? Because I've been disposing databases all around my code, and if this isn't necessary (let alone a mistake even though one without visible consequences) then I would like to know what objects am I supposed to be disposing and what objects should be left alone. Thanks.
Message 12 of 26

Tony's right on target, again it seems. Trying to dispose of stuff that will handled anyway will only slow your app down. It used to be where you had to take out the garbage. Thanks to Big Bates, there's no more need under .NET

Rudedog
"Fooling computers since 1971."
Message 13 of 26
Anonymous
in reply to: sunburned.surveyor

Very good 🙂

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Owen Wengerd" wrote in message news:5640195@discussion.autodesk.com...
Scott,

Welcome aboard.

I'm not trying to speak for Tony, but I think his post could be summarized
as "show me the money". I don't doubt that you have a lot of experience
with open source projects in some capacity, but you strike me (and obviously
Tony) as a non-programmer. You obviously have an agenda to promote open
source. Usually, this combination of traits indicates a person that
consumes open source projects instead of creating them. To old and cranky
programmers like Tony, you look like another case of a wanna-be programmer
trying to get real programmers to do the job for him. 🙂
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com
Message 14 of 26
Anonymous
in reply to: sunburned.surveyor

See below.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5639990@discussion.autodesk.com...
Tony,

>> It seems like you lack confidence in the viral nature of open source software design. I think that it may surprise you.<<

>> I don't think getting paid to write code is really an obstacle in most cases. <<

Actually it is, when people are paid to write code
(either as an employee or a consultant) they do
not own or have the rights to the code they write,
and they don't have the right to distribute it.

If your ideas about 'sharing' code were realistic,
there would be plenty of open source AutoCAD
development around, already. To the best of my
knowledge, Owen's work is all there is.

The Open Design Alliance and IntelliCAD consortium
(both of which were vicims of sabatage) are no longer
open source efforts.

>> There are a great deal of people who are professional programmers contributing to open source projects. Oftentimes this is done as part of their employment. <<

>> On one of the open source projects I work on only 2 or 3 members of the development team are volunteers. Everyone else contributes to the program on someone's payroll. <<


If their employer concedes or grants permission, that's fine.

>> Besides, I think there are probably a lot of guys like me that are just out to add a little functionality or to make a little tweak. <<<

There's a lot of guys like you running around setting up
open source projects and then sitting there and waiting
for the programmers to show up, because they are not
programmers or have the ability to do what they propose.

Anyone can create a project on SourceForge. Anyone can
create web pages that are for the most part 'invitations'
to lure programmers to do the hard part.

>> Do you doubt my qualifications, or do you question
my motives? <<

Based on the specific things you've asked for here, I
already have a pretty good idea about your qualifications.
Message 15 of 26
Anonymous
in reply to: sunburned.surveyor

Hi. Just browse the newsgroup, and you'll find them.

You can also search for keywords.

Basically, you shouldn't Dispose of things you did
not create, or things that are managed by the API
(like a Document from the DocumentsCollection, for
example).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5640459@discussion.autodesk.com...
Hi Tony, I'm very interested in your comment. Is there any post or article in particular that can help me avoid these mistakes? Because I've been disposing databases all around my code, and if this isn't necessary (let alone a mistake even though one without visible consequences) then I would like to know what objects am I supposed to be disposing and what objects should be left alone. Thanks.
Message 16 of 26

Tony,

I'm done responding to your comments. I realize at this point nothing I say will change your mind and your persepctive. You obviously aren't interested in my work and frankly you remind me of a school yard bully.

Scott Huey
Message 17 of 26
Anonymous
in reply to: sunburned.surveyor

Scott,
I qualify for old and cranky, but I'm afraid I don't have the skills of the
people you are actively antagonising. Step back man and rethink your
approach.
Perhaps you could spend some time answering question from your peers if you
want to establish a presence.

Personally I think there is an adequate collection of code floating around
penned by people who haven't yet learnt all the particulars of the language
they are supposed to be demonstrating.

Like I said, I qualify for old and cranky, and I'm also a little
opinionated.


wrote in message
news:5640760@discussion.autodesk.com...
Tony,

I'm done responding to your comments. I realize at this point nothing I say
will change your mind and your persepctive. You obviously aren't interested
in my work and frankly you remind me of a school yard bully.

Scott Huey
Message 18 of 26
Anonymous
in reply to: sunburned.surveyor

[quote]
Personally I think there is an adequate collection of code floating around
penned by people who haven't yet learnt all the particulars of the language
they are supposed to be demonstrating.
[/quote]

Did somebody call me? Hehe

Scott, Just dig in and start coding. If you run into problems or have questions, Ask! There are some great coders here that will try to help if.

1. you have code you have a problem with and you can post it
2. you have searched everywhere possible (even using the Google translator)
3. you have beat your head on the keyboard for at least 24 hours
4. offered to buy an old cranky programmer two dozen Twinkies for help

We all have our pet projects cooking. So get coding, and have fun
Message 19 of 26
Anonymous
in reply to: sunburned.surveyor

>>I'm done responding to your comments. I realize at this point nothing I
>>say will change your mind and your persepctive. You obviously aren't
>> >>interested in my work and frankly you remind me of a school yard bully.
>>
>>Scott Huey

Sunburned Surveyor;

Just have a look around here, and find out, whom is the one that have been
answer the most questions...
You will see Tony there and in most of his posts, he will be willing to
provide an extensive professional solution.

You have to be here in the ng's for a while, to know him, he is one of the
masters that have been around the customizations ng's providing so many help
always, try to get the best you can, don't take it personal, do your
homework first, and hope you have a good luck with your project.

Have fun.
Message 20 of 26
Anonymous
in reply to: sunburned.surveyor

Sunburned Surveyor,
I applaud your effort to try and get some open source code shared.

I too have found the tone of a number of members of this group as just short of offensive. It seems that one or two members have set a tone that really inhibits the sharing of information in this group.

I remember, from MANY years ago when the same members of this group would readily share their knowledge on Autolisp with any newbie in the thread. Now that they are 'professionals', they seem to feel that we newbies don't belong here and they want to point us to any other source before we are allowed to ask here. Unfortunately, I haven't been able to find those other sources. At the same time, I can't afford to become a member of ADN to get the real help I might need.

If anybody knows of good sources of examples for programming AutoCAD with .NET, please post them so we newbies can come here with intelligent questions.

The Autolisp world started with a lot of open source ideas that we all plagiarized and rebuilt into our own apps. Until there is a similar opportunity for learning .NET, the old and cranky guard here will have to filter through our questions.

Oh, and Owen, I don't think it should be an accepted initiation rite of any newsgroup that, as a newbie trying to learn, I should have to put up with Tony's sarcasm and condescending comments.

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