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

Insert field in attribute

9 REPLIES 9
Reply
Message 1 of 10
mfernandes
4414 Views, 9 Replies

Insert field in attribute

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

 

9 REPLIES 9
Message 2 of 10
cadMeUp
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#.

Message 3 of 10
mfernandes
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

 

Message 4 of 10
mfernandes
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!!!!!!

 

Message 5 of 10
cadMeUp
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.

Message 6 of 10
mfernandes
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

Message 7 of 10
cadMeUp
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.

Message 8 of 10
mfernandes
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.

 

Message 9 of 10
mfernandes
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)

 

Message 10 of 10
cadMeUp
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

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