Grasshopper

algorithmic modeling for Rhino

Hi,

I failed to do two things today. The code below are using arbitrary values to make things clear.

1. I can't set the TextHeight of the LinearDimension object

  LinearDimension myDim = new LinearDimension(new Plane(new Point3d(5, 3, 0), Vector3d.ZAxis), new Point2d(0, 0), new Point2d(10, 10), new Point2d(5, 5));


  myDim.TextHeight = 500;


  doc.Objects.AddLinearDimension(myDim);

The bold line seems to be not working because I can't see any changes of text size in the rhino document.

2. I failed to add my DimStyle Object to the LinearDimension object I created above.

  

  Rhino.DocObjects.DimensionStyle myDimStyle = new Rhino.DocObjects.DimensionStyle();

  myDimStyle.ArrowLength = 100;
  myDimStyle.TextGap = 200;
  myDimStyle.TextHeight = 500;

  int dimStyleIndex = doc.DimStyles.Add("myDimStyle", false);

  myDim.DimensionStyleIndex = dimStyleIndex;


The bold line seems to be not changing the style of my LinearDimension object.

Could anyone help me with these two failures?

Thanks!

-Jerome

Views: 2307

Replies to This Discussion

Hi Jerome,

here a sample of the second point. I am not sure I can find a way to override the styles, like you are trying to do in the first point.

I hope this helps for now. I or somebody else will look at this again.

Thanks,

- Giulio
_______________
giulio@mcneel.com

Attachments:

Hi, Giulio

Thanks for your code. 

For the first time to run your code, the dim will follow everything defined in the dimstyle.

But, if I change anything in the dimstyle such as TextHeight, toggle the boolean from true to false and back to true again, the dim will not follow those changes. Looks like it remembers the last dimstyle and it's impossible to update it.

Is this the case? Or I missed something in the process.

Thanks!

-Jerome

Hi Jerome,

please study the sample carefully. I think it's short and pretty self-explanatory, but I offer unconditionally to explain any line that is not clear.

You will notice that the code adds the new style if and only if it does not already exist. It was meant to give you a completely working introduction. Now it is up to you to make it work following your specific needs. It is definitely possible to add several dimstyles, but they should better be different instances (e.g. with a different name).

Thanks,

- Giulio
______________
giulio@mcneel.com

Thanks, Giulio

Sorry, Giulio. I misread your code. Now I can see that if the dimstyle is already there, there will not be any modification on it. I can always give a new dimstyle to my lineardimension every time I want to write them to the document. I embedded your code to my environment and it works perfectly!

Thank you again for you code and explanation!

-Jerome

Hi Jerome,

Obviously the annotation classes still need a bunch of work in RhinoCommon.  These have always not exactly been our "shining star" of classes in the SDK.

Dimensions use an associated DimensionStyle to get all of their size propreties.  The TextHeight property should probably not be available for setting on the base Annotation class since it is misleading with respect to dimensions.  I'll look into finding ways to make this all easier to use and obvious.

Currently, you can get the results that you are looking for with the following code

int dimStyleIndex = doc.DimStyles.Add("myDimStyle");

var myDimStyle = doc.DimStyles[dimStyleIndex];

myDimStyle.ArrowLength = 100;

myDimStyle.TextGap = 200;

myDimStyle.TextHeight = 500;

myDimStyle.CommitChanges(); //push changes back into document

myDim.DimensionStyleIndex = dimStyleIndex;

Thanks,

-Steve

Thanks, Steve

Thanks for you code.

The code "var myDimStyle = doc.DimStyles[dimStyleIndex];" does not seem to initialize "myDimStyle" properly. When the code goes to "myDimStyle.ArrowLength = 100;", "object reference not set to an instance of an object" error will thrown out by the compiler.

If I initialize the myDimStyle with "new" like the following code:

 int dimStyleIndex = doc.DimStyles.Add("newSytle", false);
 Rhino.DocObjects.DimensionStyle myDimStyle = new Rhino.DocObjects.DimensionStyle();
 myDimStyle = doc.DimStyles[dimStyleIndex];

Still, the same error will be thrown out.

Have I missed something important?

Thanks,

-Jerome

What value are you getting back for dimStyleIndex when you call add?  Did you try to add the same dimension style twice?

Thanks Steve,

In combination with your reply and Giulio's, now I got a clearer view about the usage of the dimstyles. Now everytime I want a new look of the lineardimension, I will give it a new dimstyle instead of trying to modify the dimstyle.

Thanks for your help!

-Jerome

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service