.NET

Reply
Mentor
mfernandes
Posts: 208
Registered: ‎08-21-2007
Message 1 of 10 (1,933 Views)

Insert field in attribute

1933 Views, 9 Replies
10-22-2010 08:40 PM

user selects a block and a vport.

program writes a field in the attribute that will display the vport scale.

 

any help or sample code is appreciated.

thanks

 

Valued Mentor
cadMeUp
Posts: 331
Registered: ‎05-11-2006
Message 2 of 10 (1,910 Views)

Re: Insert field in attribute

10-24-2010 06:22 AM in reply to: mfernandes

You can try the attached code, the sample applies the field to a text object that gets placed at the center of the viewport.

You can just apply the value to your block attribute instead, but I have not tested it that way. It can get you started, shows how to select a viewport, you can use the same method to select your block.

 

The sample is in C#.

Mentor
mfernandes
Posts: 208
Registered: ‎08-21-2007
Message 3 of 10 (1,900 Views)

Re: Insert field in attribute

10-24-2010 12:55 PM in reply to: cadMeUp

Thanks for your help, this is great stuff.

 

It seems you simpley write the field text string with the object id.

 

once again thanks

 

Mentor
mfernandes
Posts: 208
Registered: ‎08-21-2007
Message 4 of 10 (1,807 Views)

Re: Insert field in attribute

11-04-2010 05:28 PM in reply to: mfernandes

I am also now looking to add an expresion into the field, I did it manually i.e. 1 /  vport custom scale.

 

so this is what the string looks line with no expression

%<\AcObjProp Object(%<\_ObjId 8796088114864>%).CustomScale \f "%lu2%qf2816">%

 

with the expression

%<\AcExpr (1/%<\_FldPtr 760454032>%) \f "%lu2">%

 

so if I have

ID="8796088114864"

S1 = "%<\AcObjProp Object(%<\_ObjId" & ID & ">%).CustomScale \f "%lu2%qf2816">%"

S2 = "%<\AcExpr (1/%<\_FldPtr" & S1 & ">%) \f "%lu2">%"

 

does this work ???? I am thinking maybe not

HELP ug!!!!!!

 

Valued Mentor
cadMeUp
Posts: 331
Registered: ‎05-11-2006
Message 5 of 10 (1,768 Views)

Re: Insert field in attribute

11-08-2010 04:54 AM in reply to: mfernandes

Sorry so late, I'm not sure if you've figured it out:

 

string S1 = String.Format("%<\\AcExpr (1 / {0})>%",

ViewportScaleFieldFormatString(vp.ObjectId, ViewportScaleFieldFormat.None));
text.TextString = S1;

 

It should work for you.

Mentor
mfernandes
Posts: 208
Registered: ‎08-21-2007
Message 6 of 10 (1,708 Views)

Re: Insert field in attribute

11-19-2010 07:39 PM in reply to: mfernandes

Thanks, but that did not work in VB.

 

yes I am still having problems, I have got it to a point to do the calculations, however, it inserts the resulant value rather than the fielkd.

 

to create the field strind

Dim myField1 As New DatabaseServices.Field(" %<\AcExpr (1/%<\AcObjProp.16.2 Object(" + myVportID.OldIdPtr.ToString + ").CustomScale \f ""%lu2%qf2816"">%) \f ""%lu2"">%")
myField1.Evaluate()

 then to insert the field into the attribute I use

            myAttRef = myEnt.GetObject(OpenMode.ForWrite)
            myAttRef.SetField(myfield1)

 but instead of a field in the attribute, I get a value.

 

any idea, is there a simpler method

Valued Mentor
cadMeUp
Posts: 331
Registered: ‎05-11-2006
Message 7 of 10 (1,688 Views)

Re: Insert field in attribute

11-21-2010 01:05 AM in reply to: mfernandes

You can try using portions of the attatched command code.

Select a viewport, select a block, sets all 'setable' attributes within the block to the field.

The code is not commented but self explanitory...

Also attached a dwg (2010) containing a simple block with single attribute on a layout to test the command.

Mentor
mfernandes
Posts: 208
Registered: ‎08-21-2007
Message 8 of 10 (1,674 Views)

Re: Insert field in attribute

11-21-2010 12:39 PM in reply to: mfernandes

Nothing short of brilliant

Thanks, so, very much.

 

I guickly ran the program and it worked greate, now I need to step through it and understand every thing you did.

Seems you know your stuff.

 

Once again thanks.

 

Mentor
mfernandes
Posts: 208
Registered: ‎08-21-2007
Message 9 of 10 (1,606 Views)

Re: Insert field in attribute

12-03-2010 04:02 PM in reply to: mfernandes

another quick question I see for format 

Format1 i.e Format: #:1 you have the code "%lu2%qf2816:1"

however when I manually create a field in AutoCad in the evaluate field expresion I get "%lu6%ps[,:1]"

I thought I could simpley go to AutoCad to generate the syntax, then copy it and paste it into my program, it did not work

Obviously the syntax you have is correct and works, where did you get this info?

what I need is for a format that is current units with zero suppression of trailing and leading

thanks in advance.

your code that works

ViewportScaleFieldFormatString =String.Format("%<\AcObjProp Object(%<\_ObjId {0}>%).CustomScale \f ""%lu2%qf2816:1"">%", vpIdVal)

 

and this one does not

ViewportScaleFieldFormatString =String.Format("%<\AcObjProp Object(%<\_ObjId {0}>%).CustomScale \f ""%lu2%ps[,:1]"">%", vpIdVal)

 

Valued Mentor
cadMeUp
Posts: 331
Registered: ‎05-11-2006
Message 10 of 10 (1,566 Views)

Re: Insert field in attribute

12-06-2010 04:42 AM in reply to: mfernandes

I copied from the field expression box and pasted into my code file. The Custom scale property of the Viewport object doesn't give any additional formatting options so you won't be able to apply the current units and zero suppression there.

 

2328i3E876246FC1C1DB6

 

 

You can specify additional formatting in the formula evaluation portion:

 

2330iA14129198E07E3AD

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.