Anyone know how to do this in c#? I can't find any examples online. Wish vlax-put-property worked in c# lol. Thanks!
I'm away from a help file, but
pline.Elevation rings a bell.
Anyone know how to do this in c#? I can't find any examples online. Wish vlax-put-property worked in c# lol. Thanks!
Have a look at the docs for the Polyline class. It has an Elevation property..
You're probably going to have to go through the basic API training materials that Autodesk provides, to learn the basics of modifying objects in .NET. Once you've done that, doing something simple like this, only requires you to look in the docs to find the relevant class, and method or property.
The Object Browser is your friend.
The Object Browser is your friend.
//changes attributes integer value
namespace BCCADJUSTATTELEVATION
{
public class DraftingTools
{
[CommandMethod("BCC:MAV")]
public void Test()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptIntegerOptions BCCADJUST = new PromptIntegerOptions("\nEnter Amount: ");
PromptIntegerResult BCCADJUSTMENT = ed.GetInteger(BCCADJUST);
double BCCADJVALUE = BCCADJUSTMENT.Value;
{
while (0 == 0)
try
{
PromptSelectionResult psr = ed.GetSelection();
if (psr.Status != PromptStatus.OK) return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Iterate the selection set
foreach (ObjectId brId in psr.Value.GetObjectIds())
{
// Open the block reference
BlockReference br = (BlockReference)tr.GetObject(brId, OpenMode.ForRead);
ed.WriteMessage("\n\nBlock: {0}", br.Name);
// Iterate the attribute collection
foreach (ObjectId attId in br.AttributeCollection)
{
// Open the attribute reference
AttributeReference att = (AttributeReference)tr.GetObject(attId, OpenMode.ForWrite);
ed.WriteMessage("\nOld {0} = {1} ", att.Tag, att.TextString);
try
{
double ATTTODOUBLE = Convert.ToDouble(att.TextString);
double FINALVALUE = ATTTODOUBLE + BCCADJVALUE;
ed.WriteMessage("\nAdjusted {0} = {1}", att.Tag, FINALVALUE);
att.TextString = FINALVALUE.ToString();
}
catch { ed.WriteMessage("\nOne or more attributes don't contain numbers. It was skipped :)"); }
}
}
tr.Commit();
}
}
catch { ed.WriteMessage("\nBrian Says You Escaped else Failed Horribly :P"); }
}
}
}
}
:wink:
You recently jumped on someone who you thought suggested that you go back to basics. The Object Browser is the first step for the basics .. there is no easier way to say that.
Just a general tip. The AutoCad .NET API has evolved. Some old code is outdated. Sometimes Google is not your friend. Some old code is just horrible. Some new code is also horrible.
The only way to Tame the Beast is to make every line of code your own ( I mean understand it rationally) and to write lots of lines of code. If you're tempted to take that as condescending, don't ; it's a basic tenet of the art.
Regards
double BCCADJVALUE = BCCADJUSTMENT.Value;
{
while (0 == 0)
try
{
thanks Kerry!... not sure who I jumped on but I didn't mean to... I appreciate the advice :)
The object browser helped a ton, but nothing I went through on Autodesk site even mentioned it. Major fail :/
thanks Kerry!... not sure who I jumped on but I didn't mean to... I appreciate the advice :)
The object browser helped a ton, but nothing I went through on Autodesk site even mentioned it. Major fail :/
Look at the title bar at the top of your IDE.
Does it say "Autodesk Visual Studio", or does it say Microsoft Visual Studio ?
http://msdn.microsoft.com/en-us/beginner/default.aspx
How's this?Code - C#: [Select]
[CommandMethod("BCC:MAV")] public void Test() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; //PromptIntegerOptions BCCADJUST = new PromptIntegerOptions("\nEnter Amount: ");//<<--- since we arent specifying any options in here its redundant //PromptIntegerResult BCCADJUSTMENT = ed.GetInteger("\nEnter Amount: "); //double BCCADJVALUE = BCCADJUSTMENT.Value; PromptDoubleResult pdr = ed.GetDouble("\nEnter Amount: "); if (pdr.Status != PromptStatus.OK) return; //while (0==0) try { while (true)//<<--- the placement you used bothered my little brain, was stuck in my own while loop. if this loop fails, I want my program to exit { PromptSelectionResult psr = ed.GetSelection(sf);//<<<-----use a selection filter to avoid a crash on casting to block reference if (psr.Status != PromptStatus.OK) return; using (Transaction tr = db.TransactionManager.StartTransaction()) { // Iterate the selection set foreach (ObjectId brId in psr.Value.GetObjectIds()) { // Open the block reference BlockReference br = (BlockReference)tr.GetObject(brId, OpenMode.ForRead);//<<<<----- since you dont use a selection filter here this object could potentially not be a BR and crash //Could also skip selection and go forward with: //BlockReference br = tr.GetObject(brId, OpenMode.ForRead) as BlockReference; //if (br == null) continue; ed.WriteMessage("\n\nBlock: {0}", br.Name); // Iterate the attribute collection foreach (ObjectId attId in br.AttributeCollection) { // Open the attribute reference //AttributeReference att = (AttributeReference)tr.GetObject(attId, OpenMode.ForWrite);//<--- opening needlessly for write causes unneeded undo file entries //instead: AttributeReference att = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead); ed.WriteMessage("\nOld {0} = {1} ", att.Tag, att.TextString); try { double attValue = Convert.ToDouble(att.TextString);//<<---- since you are converting to double here would you be better to prompt for double instead of int? double finalValue = attValue + pdr.Value; ed.WriteMessage("\nAdjusted {0} => {1}", att.Tag, finalValue); //upgrade here because we're about to make a modification att.UpgradeOpen();//<-- we only reach this point if you are dealing with a number to be converted att.TextString = finalValue.ToString(); att.DowngradeOpen(); } catch { ed.WriteMessage("\nOne or more attributes don't contain numbers. It was skipped :)"); } } } tr.Commit(); } } } catch (System.Exception e) { Application.ShowAlertDialog(String.Format("Will Says You Failed Horribly :P\n{0}", e.Message)); } //<<<----- This function will return if the user presses escape: this code is only reached on catastrophic failure }
Cheers
WTF is this ??
looks like you have a displaced code block.
... and ( haven't analysed, so assume you use a break to escape this ) while true would be a more usual conditional.Code: [Select]double BCCADJVALUE = BCCADJUSTMENT.Value;
{
while (0 == 0)
try
{
thanks Kerry!... not sure who I jumped on but I didn't mean to... I appreciate the advice :)
The object browser helped a ton, but nothing I went through on Autodesk site even mentioned it. Major fail :/
Look at the title bar at the top of your IDE.
Does it say "Autodesk Visual Studio", or does it say Microsoft Visual Studio ?
http://msdn.microsoft.com/en-us/beginner/default.aspx
Thanks TT... man you guys are ruthless... no mercy I suppose.... seems a culture of condemnation in the programmers world...
Thanks TT... man you guys are ruthless... no mercy I suppose.... seems a culture of condemnation in the programmers world...
If you aren't familiar with it, look up "RTFM".
Thanks TT... man you guys are ruthless... no mercy I suppose.... seems a culture of condemnation in the programmers world...
Well, there may be a few here with something to prove, that might serve as motivation for giving you free training and tutoring on something that you barely understand, but unfortunately, I'm not one of them.
The reason that you're wearing out your welcome so quickly, and the reason you characterize some here as being part of a 'culture of condemnation', is because you are here trying to get spoon-fed, what most of us had to get through a lot of hard work, self-learning, paid-for-learning, and more generally, making the personal effort to learn to walk before trying to run, and did that without burdening others in an online discussion group with what amounts to free training.
... For the 'visual learners':If you aren't familiar with it, look up "RTFM".
(http://www.cadtutor.net/forum/images/smilies/rtfm.gif)
Thanks TT... man you guys are ruthless... no mercy I suppose.... seems a culture of condemnation in the programmers world...
This is the friendly end of the pool. In the more... "dedicated" ... recesses of the online programming community you would be *vigorously* ripped a new one for not doing the initial leg work. Part of it stems from the experience of inheriting somebody elses code which came from similar starting points and now doesn't work, requring serious analysis and/or a full re-write while execs are breathing down your neck.
If you aren't familiar with it, look up "RTFM".
thanks Kerry!... not sure who I jumped on but I didn't mean to... I appreciate the advice :)
The object browser helped a ton, but nothing I went through on Autodesk site even mentioned it. Major fail :/
Look at the title bar at the top of your IDE.
Does it say "Autodesk Visual Studio", or does it say Microsoft Visual Studio ?
http://msdn.microsoft.com/en-us/beginner/default.aspx
In an effort to build on Tony's excellent point (if I may)... I think you're (BC) overlooking development concepts generally with what I presume to be unintentional 'Autodesk blinders' on. This is unfortunately very common when stepping up from LISP to .NET API.
Given Object Oriented development as a whole, despite growing with each release, the Autodesk .NET API is a very tiny, perhaps minuscule, arena of the former.
If your goal is to become a capable AutoCAD .NET developer, then it is an essential, yet implied task, that you (first?) become a capable .NET developer (i.e., Console, Windows Forms, WPF Browser Applications, etc. to list a few), as while not explicitly stated in all beginner AutoCAD .NET materials, it can easily be considered to be a prerequisite... Particularly as you spill over into more complex tasks, and frameworks.
There are many free resources out there (some of which are available directly from Visual Studio's Start Page), but if you'd like to find a book to read, and re-read again, I found Andrew Troelsen's Pro C# 2010 and the .NET 4 Platform (http://www.amazon.com/2010-NET-Platform-Andrew-Troelsen/dp/1430225491/ref=sr_1_5?ie=UTF8&qid=1360701652&sr=8-5&keywords=C%23) to be useful... All +1700 pages of it.
Andrew's Pro C# 5.0 and the .NET 4.5 Platform (http://www.amazon.com/Pro-NET-Framework-Professional-Apress/dp/1430242337/ref=sr_1_3?ie=UTF8&qid=1360701652&sr=8-3&keywords=C%23) is also available for those who may be interested... Perhaps for the 2014 product line? *not sure*
... [NDA Censorship]
BC, I think you're taking this as some sort of personal attack, when in fact it is not... Especially among the programming kind, members tend to speak very matter-of-fact.
I just started the ascension from LISP to .NET myself recently... I may have an aptitude for development, but I could not have come as far as I have in (what I consider to be) such a short time-frame _without_ the help of others on this, and other forums alike (this one's the best though - giggity). That is why I strive to give back, where I feel it may be of use to others.
You're just starting to climb the proverbial mountain... Immerse yourself in the .NET documentation, tutorials, read related threads to help you troubleshoot, etc.. and for the love of all that is good, code, code, and code some more.
Methinks, it's the only way _you're_ going to learn (not just you, but anyone in this situation)... When you get stuck (and you will), post a clear, descriptive post, and don't forget to include some code (pseudo code is fine).
While I cannot speak for others, if my limited experience is any indicator, I'd bet a hot dollar that any one of the members you think is blasting you now (provided you follow the aforementioned suggestions), would gladly help to point you in the right direction. Just my $0.02.
< .. >I can't argue with that ...
The reason I have a bad reaction to people who are complete noobs, and are expecting to be able to do what requires a good years worth of learning and practice, is because we generally communicate with others with an assumption that the other person can understand what is being written, the terms we use in what we write, etc., and that terms that most of us may take for granted as being understood, are not understood by a total noob.
So, to explain things to the noob, you have recursively explain things in your explaination, distilled down to terms they can understand, which means you have to write a #$%^ book for them, and in some cases, they seem to be expecting nothing less than that.
The reason I have a bad reaction to people who are complete noobs, and are expecting to be able to do what requires a good years worth of learning and practice, is because we generally communicate with others with an assumption that the other person can understand what is being written, the terms we use in what we write, etc., and that terms that most of us may take for granted as being understood, are not understood by a total noob.
So, to explain things to the noob, you have recursively explain things in your explaination, distilled down to terms they can understand, which means you have to write a #$%^ book for them, and in some cases, they seem to be expecting nothing less than that.
I am unsure if you felt that my response was in any way directed at you, Tony... Regardless, I don't believe a reasonable person would take issue with the sentiment you conveyed here.
This is a public forum, made up of volunteer members who kindly donate their time, effort, knowledge, and often wisdom... Something that is to be respected from the outset, each time one chooses to become the question-asker.
RenderMan, no, I just replied to the last post, nothing about it that I took issue with.
I just wanted to clarify my position.