Dim Closed Polylines

Hi everybody
I am having a problem.

    import rhinoscriptsyntax as rs
    import scriptcontext as sc
    import Rhino

    def GetOffsetMidpoints(pl_ID,dist,plane):
        #get offset figure and offset points
        bb=rs.BoundingBox(pl_ID)
        xform=rs.XformScale(1.1,(bb[0]+bb[2])/2)
        bb=rs.PointArrayTransform(bb,xform)
        pl=rs.coercecurve(pl_ID)
        sharp=Rhino.Geometry.CurveOffsetCornerStyle.Sharp
        off_pl=pl.Offset(bb[2],plane.Normal,dist,sc.doc.ModelAbsoluteTolerance,sharp)
        if off_pl:
            segs=off_pl[0].DuplicateSegments()
            mids=[(seg.PointAtStart+seg.PointAtEnd)/2 for seg in segs]
            return mids
        
    #closed planar polyline filter
    def pl_filt(rhino_object, geometry, component_index):
        return rs.IsPolyline(geometry) and rs.IsCurveClosed(geometry) and rs.IsCurvePlanar(geometry)

    def DimClosedPolylines2():
        msg="Select polylines to dimension"
        pl_IDs=rs.GetObjects(msg,4,preselect=True,custom_filter=pl_filt)
        if not pl_IDs: return
        dist=rs.GetReal("Distance to offset?",5,0)
        if dist is None: return
        
        rs.EnableRedraw(False)
        
        dimStyle = CreateDimStyle(dist)
        #Create a DimStyle
        for pl_ID in pl_IDs:
            verts=rs.PolylineVertices(pl_ID)
            opts=GetOffsetMidpoints(pl_ID,dist,rs.CurvePlane(pl_ID))
            if opts:
                #checksum in case offset went wrong
                if len(opts)+1==len(verts):
                    for i in range(len(verts)-1):
                        dim = rs.AddAlignedDimension(verts[i],verts[i+1],opts[i],dimStyle)


    def CreateDimStyle(textHeight):
        dimStyle_name = "MyDim"
        dimStyle = rs.AddDimStyle(dimStyle_name)
        rs.DimStyleTextHeight(dimStyle,textHeight)
        rs.DimStyleArrowSize(dimStyle,textHeight)
        return dimStyle


    DimClosedPolylines2()

Hi @rhinoceros.adv,

Sorry I’m ignorant - what exactly is the problem? Or better yet, what are you trying to?

Thanks,

– Dale

I want to change the values ​​

@Alain - is this something you can help with?

1 Like

Hi,
Once you’ve positioned your dimensions in the location you want you can either adjust the extension line offset OR make the extension line a fixed length.

  1. set ExtensionLineOffset to desired value and make sure FixedLengthExtensionOn is False (False is the default). The extension line will grow to offset value and FixedExtensionLength is be ignored.

  2. set FixedExtensionLength to desired value and make sure FixedLengthExtensionOn is True. The extension line length will be fixed and ExtensionLineOffset is be ignored.

Does that help?

Thanks you all

Trying to learn from this one as well.

The object reports as a dim (true), but the rhinocommon wants a dim but gets the guid.

Here’s a simple example:

import rhinoscriptsyntax as rs
from scriptcontext import doc
from Rhino.Geometry import Plane

id = rs.AddLinearDimension(Plane.WorldXY, (0,0,0), (20,0,0), (10,5,0))
o = doc.Objects.FindId(id)
d = o.Geometry

# give extension lines a fixed length of 2
d.FixedLengthExtensionOn = True
d.FixedExtensionLength = 2.0

# give extension lines an offset of 1
#d.FixedLengthExtensionOn = False
#d.ExtensionLineOffset = 1

o.CommitChanges()
rs.Redraw()
2 Likes

Hello
For example, my friend ran unsuccessfully

I copied and pasted and ran it, works fine. I even integrated into your script successfully.

You will have to be more specific. Is there a line that it failed at?

I have just tried

Sorry for any confusion, that was a post asking how to solve (i don’t know how to code)

The expert answer is this one…


import rhinoscriptsyntax as rs
from scriptcontext import doc
from Rhino.Geometry import Plane

id = rs.AddLinearDimension(Plane.WorldXY, (0,0,0), (20,0,0), (10,5,0))
o = doc.Objects.FindId(id)
d = o.Geometry

# give extension lines a fixed length of 2
d.FixedLengthExtensionOn = True
d.FixedExtensionLength = 2.0

# give extension lines an offset of 1
#d.FixedLengthExtensionOn = False
#d.ExtensionLineOffset = 1

o.CommitChanges()
rs.Redraw()

This code I run also do not see anything displayed

in your code it looks like this…


def DimClosedPolylines2():
    msg="Select polylines to dimension"
    pl_IDs=rs.GetObjects(msg,4,preselect=True,custom_filter=pl_filt)
    if not pl_IDs: return
    dist=rs.GetReal("Distance to offset?",5,0)
    if dist is None: return
    
    rs.EnableRedraw(False)
    
    dimStyle = CreateDimStyle(dist)
    #Create a DimStyle
    for pl_ID in pl_IDs:
        verts=rs.PolylineVertices(pl_ID)
        opts=GetOffsetMidpoints(pl_ID,dist,rs.CurvePlane(pl_ID))
        if opts:
            #checksum in case offset went wrong
            if len(opts)+1==len(verts):
                for i in range(len(verts)-1):
                    dim = rs.AddAlignedDimension(verts[i],verts[i+1],opts[i],dimStyle)
                    dimid = sc.doc.Objects.FindId(dim)
                    dimG = dimid.Geometry
                    dimG.FixedLengthExtensionOn = False
                    dimG.ExtensionLineOffset = 50.0
                    dimid.CommitChanges()
                    rs.Redraw()

note that the offset is just an arbitrary number for testing.

thank you. I will try it tomorrow. good night

Chúc ngủ ngon

Thanks you

What offset are you trying to affect? Do note that as you change the offset it changes the textHeight.

def DimClosedPolylines2():
    msg="Select polylines to dimension"
    pl_IDs=rs.GetObjects(msg,4,preselect=True,custom_filter=pl_filt)
    if not pl_IDs: return
    dist=rs.GetReal("Distance to offset?",20,0)
    if dist is None: return
    
    rs.EnableRedraw(False)
    
    dimStyle = CreateDimStyle(dist)
    #Create a DimStyle
    for pl_ID in pl_IDs:
        verts=rs.PolylineVertices(pl_ID)
        opts=GetOffsetMidpoints(pl_ID,dist,rs.CurvePlane(pl_ID))
        if opts:
            #checksum in case offset went wrong
            if len(opts)+1==len(verts):
                for i in range(len(verts)-1):
                    dim = rs.AddAlignedDimension(verts[i],verts[i+1],opts[i],dimStyle)
                    dimid = sc.doc.Objects.FindId(dim)
                    dimG = dimid.Geometry
                    dimG.FixedLengthExtensionOn = False
                    dimG.ExtensionLineOffset = 5.0
                    dimid.CommitChanges()
                    rs.Redraw()

Let me see your results. thanks

No i’m not Vietnamese, i just eat a lot of Pho, Bahn Mi etc.

What exactly are you trying to accomplish???

dist=rs.GetReal("Distance to offset?",20,0)

# give extension lines an offset of 1
d.FixedLengthExtensionOn = False
d.ExtensionLineOffset = 5

# give extension lines a fixed length of 2
#d.FixedLengthExtensionOn = True
#d.FixedExtensionLength = 2.0



1 Like