Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy user defined attribute to raw description using .net

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
samthomasdigital
676 Views, 7 Replies

Copy user defined attribute to raw description using .net

Hi Jeff,

 

I am trying to write a script to do the following.

 

For each (cogo point in drawing)

                {

                If (Raw description == THISCODE*)

                                {

                                Replace THISCODE with User defined attribute 1

                                }

                applyDescriptionKey()

                }

 

I am running Civil 3D 2013.

 

Having read through a few of your other threads I noticed that applyDescriptionKey() is 2013 specific.

 

Cheers,

 

Sam

7 REPLIES 7
Message 2 of 8
Jeff_M
in reply to: samthomasdigital

Hi Sam,

I hope you don't get used to someone whipping out some quick code Smiley Very Happy but I was actually working on something similar recently so I kindof already had some test code here. This should more than get you started. How fluent are you in C#? You will need to add teh appropriate References and using statements...

private void swapdescforudp(string description, UDPString udp)
        {
            CivilDocument civdoc = CivilApplication.ActiveDocument;
            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in civdoc.GetAllPointIds())
                {
                    CogoPoint pt = (CogoPoint)id.GetObject(OpenMode.ForRead);
                    if (pt.RawDescription == description)
                    {
                        try
                        {
                            pt.UpgradeOpen();
                            pt.RawDescription = pt.GetUDPValue(udp);
                            pt.ApplyDescriptionKeys();
                        }
                        catch { }
                        finally { pt.DowngradeOpen(); }
                    }
                }
                
                tr.Commit();
            } 
        }

        [CommandMethod("UDPToDesc")]
        public void udptodesccommand()
        {
            string udpname = "TEST";
            UDPString udp = null;
            CivilDocument civdoc = CivilApplication.ActiveDocument;
            foreach (UDP obj in civdoc.PointUDPs)
            {
                if (obj.Name == udpname)
                {
                    udp = (UDPString)obj;
                    break;
                }
            }
            if (udp == null)
                return;
            swapdescforudp("test", udp);
        }

 

 

 

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 8
samthomasdigital
in reply to: Jeff_M

Hey Jeff,

 

What you sent me looks excellent! I have some perl knowledge that google taught me but C# looks fairly similar.

 

I really appreciate the help and I should be able to tweak it myself from here. 

 

I'll let you know how I go.

 

You're a legend!

 

Sam

Message 4 of 8

Hey Jeff,

 

I worked through the Civil 3D API developers guide and got it working! Thanks for the (massive) head start. Much appreciated.

 

Sam.

Message 5 of 8
Jeff_M
in reply to: samthomasdigital

Glad I could help, Sam. Now, if you could mark the post that helped you as the solution instead of your own post... Smiley Happy

 

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 8
samthomasdigital
in reply to: Jeff_M

Hey Jeff!

 

I have modified the code so that it takes both attributes 1 and 2 then concatenates them. It was all going great until I realised that I can't access the Survey User-Defined Attributes. I can't find any documentation on this in the developers guide. Do you know if it is possible?

 

Cheers,

 

Sam

Message 7 of 8
Jeff_M
in reply to: samthomasdigital

Can you post a small sample file? I don't use the Survey DB so I'm not sure... Are you accessing the points in the DB before adding them to the drwing, or are these Survey points in the drawing?

Jeff_M, also a frequent Swamper
EESignature
Message 8 of 8
samthomasdigital
in reply to: Jeff_M

Hey Jeff,

 

I had a custom import format file that when I was importing the CSV as survey data Civil 3D was creating another set of attributes Survey User-Defined that I couldn't access through my dll. But...

 

I found a better way! If I import the points the traditional way then add them to a survey database afterwards I don't get the duplicate attributes and I can use the code you supplied me.

 

I would have had to modify all the labels styles to include either Attribute 1 or the new one that was created on import Point.Attibute 1 anyway. Painful.

 

Thanks for the help. Should be all good now.

 

Sam

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report