Author Topic: Anyone have example for changing z elevation of polyline?  (Read 10712 times)

0 Members and 1 Guest are viewing this topic.

bchapman

  • Guest
Anyone have example for changing z elevation of polyline?
« on: February 11, 2013, 02:53:40 AM »
Anyone know how to do this in c#?  I can't find any examples online. Wish vlax-put-property worked in c# lol.  Thanks!
« Last Edit: February 11, 2013, 03:26:32 AM by BC_in_NV »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Anyone have example for changing z elevation of polyline?
« Reply #1 on: February 11, 2013, 04:44:09 AM »
I'm away from a help file, but
pline.Elevation rings a bell.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

TheMaster

  • Guest
Re: Anyone have example for changing z elevation of polyline?
« Reply #2 on: February 11, 2013, 12:38:51 PM »
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.


bchapman

  • Guest
Re: Anyone have example for changing z elevation of polyline?
« Reply #3 on: February 11, 2013, 01:01:08 PM »
Thanks!

I'm away from a help file, but
pline.Elevation rings a bell.

BlackBox

  • King Gator
  • Posts: 3770
Re: Anyone have example for changing z elevation of polyline?
« Reply #4 on: February 11, 2013, 01:01:36 PM »
The Object Browser is your friend.
"How we think determines what we do, and what we do determines what we get."

bchapman

  • Guest
Re: Anyone have example for changing z elevation of polyline?
« Reply #5 on: February 11, 2013, 01:05:30 PM »
Thanks TT... I needed to know the name of what I was looking for. Went through the labs and the "my first plug in" but those are developed for the slightly more aggressive programmer with some programming education it seems...

Desperately needed the method or whatever you and Kerry posted so I could find the document you are talking about. every time I search for it I pull up a thousand things I don't care about lol

Don't get me wrong... I might back track if I have to :/ My end goal is simply to get the routines I've written into C#... if I plan on programming beyond that... I may have to

Thanks!


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.
« Last Edit: February 11, 2013, 01:14:21 PM by BC_in_NV »

bchapman

  • Guest
Re: Anyone have example for changing z elevation of polyline?
« Reply #6 on: February 11, 2013, 10:55:37 PM »
Thank you renderman!!! I desperately needed that.  That really should be the first thing on any lesson

The Object Browser is your friend.

bchapman

  • Guest
Re: Anyone have example for changing z elevation of polyline?
« Reply #7 on: February 12, 2013, 03:03:38 AM »
I want to second the kudos for this comment!  Frick I needed this so much sooner :)  Thanks again RM, saved me bacon as always!

The Object Browser is your friend.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Anyone have example for changing z elevation of polyline?
« Reply #8 on: February 12, 2013, 05:03:07 AM »

 :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

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

bchapman

  • Guest
Re: Anyone have example for changing z elevation of polyline?
« Reply #9 on: February 12, 2013, 05:17:45 AM »
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 :/  Wish I didn't have to but seems the only way to learn this stuff is to rely on people like you to continue to share what you've learned, and written, and hope the day doesn't come when you, and others like you, decide to stop sharing :/  There's something to be said about the satisfaction of getting a piece of code working, whether written by one self entirely, or modifying anothers to do what one would want.

This is my latest disaster... unfortunately I've not got away from CAPs yet... but I do feel I'm understanding it a little better... not much...but some....

Code: [Select]
//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
« Last Edit: February 12, 2013, 05:28:02 AM by BC_in_NV »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Anyone have example for changing z elevation of polyline?
« Reply #10 on: February 12, 2013, 08:50:03 AM »
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
                    {


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Anyone have example for changing z elevation of polyline?
« Reply #11 on: February 12, 2013, 11:17:15 AM »
How's this?


Code - C#: [Select]
  1.         [CommandMethod("BCC:MAV")]
  2.         public void Test()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Database db = doc.Database;
  6.             Editor ed = doc.Editor;
  7.  
  8.             //PromptIntegerOptions BCCADJUST = new PromptIntegerOptions("\nEnter Amount: ");//<<--- since we arent specifying any options in here its redundant
  9.             //PromptIntegerResult BCCADJUSTMENT = ed.GetInteger("\nEnter Amount: ");
  10.             //double BCCADJVALUE = BCCADJUSTMENT.Value;
  11.             PromptDoubleResult pdr = ed.GetDouble("\nEnter Amount: ");
  12.             if (pdr.Status != PromptStatus.OK) return;
  13.  
  14.             SelectionFilter sf = new SelectionFilter(new TypedValue[1] { new TypedValue((int)DxfCode.Start, "INSERT") });//<<<--- a selection filter to get only block references
  15.  
  16.             //while (0==0)
  17.             try
  18.             {
  19.                 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
  20.                 {
  21.                     PromptSelectionResult psr = ed.GetSelection(sf);//<<<-----use a selection filter to avoid a crash on casting to block reference
  22.                     if (psr.Status != PromptStatus.OK) return;
  23.  
  24.                     using (Transaction tr = db.TransactionManager.StartTransaction())
  25.                     {
  26.                         // Iterate the selection set
  27.                         foreach (ObjectId brId in psr.Value.GetObjectIds())
  28.                         {
  29.                             // Open the block reference
  30.                             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
  31.                             //Could also skip selection and go forward with:
  32.                             //BlockReference br = tr.GetObject(brId, OpenMode.ForRead) as BlockReference;
  33.                             //if (br == null) continue;
  34.                             ed.WriteMessage("\n\nBlock: {0}", br.Name);
  35.                             // Iterate the attribute collection
  36.                             foreach (ObjectId attId in br.AttributeCollection)
  37.                             {
  38.                                 // Open the attribute reference
  39.                                 //AttributeReference att = (AttributeReference)tr.GetObject(attId, OpenMode.ForWrite);//<--- opening needlessly for write causes unneeded undo file entries
  40.                                 //instead:
  41.                                 AttributeReference att = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead);
  42.                                 ed.WriteMessage("\nOld {0} = {1} ", att.Tag, att.TextString);
  43.  
  44.                                 try
  45.                                 {
  46.                                     double attValue = Convert.ToDouble(att.TextString);//<<---- since you are converting to double here would you be better to prompt for double instead of int?
  47.  
  48.  
  49.                                     double finalValue = attValue + pdr.Value;
  50.  
  51.                                     ed.WriteMessage("\nAdjusted {0} => {1}", att.Tag, finalValue);
  52.                                     //upgrade here because we're about to make a modification
  53.                                     att.UpgradeOpen();//<-- we only reach this point if you are dealing with a number to be converted
  54.                                     att.TextString = finalValue.ToString();
  55.                                     att.DowngradeOpen();
  56.                                 }
  57.                                 catch { ed.WriteMessage("\nOne or more attributes don't contain numbers. It was skipped :)"); }
  58.                             }
  59.                         }
  60.                         tr.Commit();
  61.                     }
  62.                 }
  63.             }
  64.             catch (System.Exception e)
  65.             { 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
  66.  
  67.         }

Cheers

TheMaster

  • Guest
Re: Anyone have example for changing z elevation of polyline?
« Reply #12 on: February 12, 2013, 01:15:23 PM »
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


bchapman

  • Guest
Re: Anyone have example for changing z elevation of polyline?
« Reply #13 on: February 12, 2013, 03:39:25 PM »
Thanks TT... man you guys are ruthless... no mercy I suppose.... seems a culture of condemnation in the programmers world...

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
« Last Edit: February 12, 2013, 03:48:07 PM by BC_in_NV »

bchapman

  • Guest
Re: Anyone have example for changing z elevation of polyline?
« Reply #14 on: February 12, 2013, 03:40:26 PM »
Thanks Will!! I'll review it carefully.

How's this?


Code - C#: [Select]
  1.         [CommandMethod("BCC:MAV")]
  2.         public void Test()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Database db = doc.Database;
  6.             Editor ed = doc.Editor;
  7.  
  8.             //PromptIntegerOptions BCCADJUST = new PromptIntegerOptions("\nEnter Amount: ");//<<--- since we arent specifying any options in here its redundant
  9.             //PromptIntegerResult BCCADJUSTMENT = ed.GetInteger("\nEnter Amount: ");
  10.             //double BCCADJVALUE = BCCADJUSTMENT.Value;
  11.             PromptDoubleResult pdr = ed.GetDouble("\nEnter Amount: ");
  12.             if (pdr.Status != PromptStatus.OK) return;
  13.  
  14.             SelectionFilter sf = new SelectionFilter(new TypedValue[1] { new TypedValue((int)DxfCode.Start, "INSERT") });//<<<--- a selection filter to get only block references
  15.  
  16.             //while (0==0)
  17.             try
  18.             {
  19.                 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
  20.                 {
  21.                     PromptSelectionResult psr = ed.GetSelection(sf);//<<<-----use a selection filter to avoid a crash on casting to block reference
  22.                     if (psr.Status != PromptStatus.OK) return;
  23.  
  24.                     using (Transaction tr = db.TransactionManager.StartTransaction())
  25.                     {
  26.                         // Iterate the selection set
  27.                         foreach (ObjectId brId in psr.Value.GetObjectIds())
  28.                         {
  29.                             // Open the block reference
  30.                             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
  31.                             //Could also skip selection and go forward with:
  32.                             //BlockReference br = tr.GetObject(brId, OpenMode.ForRead) as BlockReference;
  33.                             //if (br == null) continue;
  34.                             ed.WriteMessage("\n\nBlock: {0}", br.Name);
  35.                             // Iterate the attribute collection
  36.                             foreach (ObjectId attId in br.AttributeCollection)
  37.                             {
  38.                                 // Open the attribute reference
  39.                                 //AttributeReference att = (AttributeReference)tr.GetObject(attId, OpenMode.ForWrite);//<--- opening needlessly for write causes unneeded undo file entries
  40.                                 //instead:
  41.                                 AttributeReference att = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead);
  42.                                 ed.WriteMessage("\nOld {0} = {1} ", att.Tag, att.TextString);
  43.  
  44.                                 try
  45.                                 {
  46.                                     double attValue = Convert.ToDouble(att.TextString);//<<---- since you are converting to double here would you be better to prompt for double instead of int?
  47.  
  48.  
  49.                                     double finalValue = attValue + pdr.Value;
  50.  
  51.                                     ed.WriteMessage("\nAdjusted {0} => {1}", att.Tag, finalValue);
  52.                                     //upgrade here because we're about to make a modification
  53.                                     att.UpgradeOpen();//<-- we only reach this point if you are dealing with a number to be converted
  54.                                     att.TextString = finalValue.ToString();
  55.                                     att.DowngradeOpen();
  56.                                 }
  57.                                 catch { ed.WriteMessage("\nOne or more attributes don't contain numbers. It was skipped :)"); }
  58.                             }
  59.                         }
  60.                         tr.Commit();
  61.                     }
  62.                 }
  63.             }
  64.             catch (System.Exception e)
  65.             { 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
  66.  
  67.         }

Cheers