+ Reply to Thread
Results 1 to 10 of 10

Thread: RhinoCommon DimStyle question

  1. #1
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    313

    RhinoCommon DimStyle question

    Hi,

    Dumb question here, but I still really don't understand all of how stuff in document tables work

    I can get the value of a property (such as centermark size) of the current dimension style with this:

    cms=scriptcontext.doc.DimStyles.CurrentDimensionSt yle.CenterMarkSize

    or of another dimension style in the document with this:

    cms=scriptcontext.doc.DimStyles[n].CenterMarkSize
    (n being the index of the dim style)

    But how do I change these values?

    Thanks,
    --Mitch

  2. #2
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,472
    Blog Entries
    19
    Hi Mitch,
    Set the CenterMarkSize and whatever other properties you want and then when you are done and happy with your result, call CommitChanges()
    Python Code:
      ds = scriptcontext.doc.DimStyles[n]
      ds.CenterMarkSize = 1234
      ds.CommitChanges()

  3. #3
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    313
    OK, cool thanks - I saw CommitChanges and wondered if that was its purpose but I didn't know how it should be used. This should be enough to get me where I need to go, I'll check back in if it isn't.
    Cheers,
    --Mitch

  4. #4
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    313
    Hmm, I get this when I try the above... :
    Message: 'DimensionStyle' object has no attribute 'CommmitChanges'

    Below is the entire script:
    Python Code:
      import rhinoscriptsyntax as rs
      import scriptcontext
       
      def CopyScaleDimstyle2():
         
          ds=scriptcontext.doc.DimStyles
          dsCount=scriptcontext.doc.DimStyles.Count
          dsDict={scriptcontext.doc.DimStyles[n].Name : n for n in range(dsCount)}
         
          title="Copy/Scale Dimension Style"
          choice=rs.ListBox(dsDict.keys(),"Pick a dim style to copy and scale",title)
          if choice is None: return
          n=dsDict[choice]
       
          nameOK=False
          while nameOK==False:
              newName=rs.StringBox("Name must be unique!",choice+"-1","Enter new style name")
              if newName is None: return
              if newName in dsDict:
                  rs.MessageBox("Name already exists - please choose another!")
              else:
                  nameOK=True
         
          sf=rs.RealBox("Scale factor?",2,"Scale factor")
          if sf is None: return
          if sf<=0:
              print "Scale factor must be greater than 0"
              return
             
          rs.AddDimStyle(newName)
          #assume new style is added to end of list, dsCount should now be dsCount+1
          #apply scale to the different fields
          ds[dsCount].Name=newName
          ds[dsCount].TextHeight=ds[n].TextHeight*sf
          ds[dsCount].TextGap=ds[n].TextGap*sf
          ds[dsCount].ExtensionLineExtension=ds[n].ExtensionLineExtension*sf
          ds[dsCount].ExtensionLineOffset=ds[n].ExtensionLineOffset*sf
          #the following property is missing... :-(
          #ds[dsCount].DimensionLineExtension=ds[n].DimensionLineExtension*sf
          ds[dsCount].CenterMarkSize=ds[n].CenterMarkSize*sf
          ds[dsCount].ArrowLength=ds[n].ArrowLength*sf
          ds[dsCount].LeaderArrowLength=ds[n].LeaderArrowLength*sf
          #Apply changes to new style
          ds[dsCount].CommmitChanges()
          #Below gives no error message but does nothing
          #scriptcontext.doc.DimStyles[dsCount].CommitChanges
       
      CopyScaleDimstyle2()

    ??? -Mitch

  5. #5
    I think it's the 'Commmit...' typo.

    Regards Conrad

  6. #6
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    313
    OK, yeah, that produced the error message... I am definitely ashamed..
    However, now, even though it doesn't error out, it doesn't do anything either... The new dim style is unchanged, it still has the same characteristics as the style it was copied from.

  7. #7
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,472
    Blog Entries
    19
    Hi Mitch,
    The problem is that you are continuously asking the document for DimStyle at dsCount. I realize this is a bit confusing since everything does appear to work and it may be a poor design decision on my part when putting RhinoCommon together, but let me explain.

    When you call ds[dsCount].Name=newName, the code is asking the dimstyle table for an existing dimstyle and hands it back as a variable. You are then changing the name on this local variable and throwing it away on the next line by asking the dimstyle table for an existing dimstyle again.

    Fortunately this is easily remedied by saving the one variable, modifying it, and then calling CommitChanges to push your changed back on the document.

    Python Code:
      modified_ds = ds[dsCount]
      modified_ds.Name=newName
      modified_ds.TextHeight=ds[n].TextHeight*sf
      modified_ds.TextGap=ds[n].TextGap*sf
      ...
      modified_ds.CommitChanges()

    I hope this makes sense. If not please let me know and I'll try to explain in a bit more detail.
    Thanks,
    -Steve

  8. #8
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    313
    Hi Steve,
    Well, no not really... I had just assumed that the dimstyle had a set of properties that could be modified but would not be added back to the document unless you called CommitChanges. I assumed that when you ran ds[dsCount].Name=newName that the newName modified the dimstyle's property, as normally the value on the right side of the = is assigned to the object on the left... I can see that I'm a bit out of my depth here...

    --Mitch

  9. #9
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,472
    Blog Entries
    19
    Hi Mitch,
    I completely understand your confusion and wish I had a cleaner/clearer implementation. Hopefully I'll be able to come up with something in the future that makes more sense, but for now if you follow my recommendation of assigning the dimstyle to a variable, adjusting the variable, and then calling CommitChanges() your script should work.

    Thanks,
    -Steve

  10. #10
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    313
    Ok, that works... thanks! Can you get the DimensionLineExtension property in there? By default it's 0, so scaling it will still be 0, but for completeness it should be there...
    --Mitch

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts