Match properties hatch pattern Rhino8

in rhino8 match properties can’t match pattern and properties two hatch for example size, rotation,…
if it isn’t Bug please add this features like match properties in autocad,…
This bug causes slow performance and work with Rhino 8
@mary
@pascal

You should be able do this directly through the Properties panel, select the hatches to change, hit the Match button in the panel, select the hatch to match. But, it does not appear to be working at the moment… @pascal also…

1 Like

Yep, this looks busted, thanks.

RH-82678 Hatch match properties fails

-Pascal

2 Likes

If you are on Rhino 8, i have a script for matchproperties that works more like autocad. It works on text, hatches, dimensions and geometry. I also have script for offset thats more similar to autocad (doesnt exit after the first offset, and offsetted items keep layer, linetype information etc).
I can post it if you want it

1 Like

@mich.platter please share it! :pray:

Sure

// #! csharp
// AcadMatchProperties.cs

using System;
using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Geometry;

var doc = RhinoDoc.ActiveDoc;
bool opMPCopyAttrUserText;

if(doc.RuntimeData.ContainsKey("opMPCopyAttrUserText"))
   opMPCopyAttrUserText = (doc.RuntimeData["opMPCopyAttrUserText"] == "On") ? true : false;
else
{
   doc.RuntimeData.Add("opMPCopyAttrUserText", "Off");
   opMPCopyAttrUserText = false;
}

var inputFilter = ObjectType.Annotation | ObjectType.Brep | ObjectType.ClipPlane | ObjectType.Curve | ObjectType.Detail | ObjectType.Extrusion | ObjectType.Hatch | ObjectType.Light | ObjectType.Mesh | ObjectType.Point | ObjectType.SubD | ObjectType.Surface | ObjectType.TextDot;
Rhino.Input.RhinoGet.GetOneObject("Select source object", false, inputFilter, out var srcObjRef);
if(null == srcObjRef)
   return;
var srcObj = srcObjRef.Object();
doc.Objects.UnselectAll(false);

var go = new Rhino.Input.Custom.GetObject();
go.SetCommandPrompt("Select target objects");
go.GeometryFilter = inputFilter;
go.EnableClearObjectsOnEntry(false);
go.EnableUnselectObjectsOnExit(false);
go.DeselectAllBeforePostSelect = false;

var copyMPAttrUserTextOption = new Rhino.Input.Custom.OptionToggle(opMPCopyAttrUserText, "Off", "On");
go.AddOptionToggle("CopyAttributeUserText", ref copyMPAttrUserTextOption);

for(;;)
{
   var rc = go.GetMultiple(1, 0);

   if(go.CommandResult() != Result.Success || null == go.Object(0))
       break;
   else if (rc == Rhino.Input.GetResult.Option)
   {
       go.EnablePreSelect(false, true);
       opMPCopyAttrUserText = copyMPAttrUserTextOption.CurrentValue;
       doc.RuntimeData["opMPCopyAttrUserText"] = opMPCopyAttrUserText ? "On" : "Off";
       continue;
   }
   break;
} 

foreach (var tgtItem in go.Objects())
{
   var tgtObj = tgtItem.Object();
   tgtObj.Attributes = srcObj.Attributes.Duplicate();
   tgtObj.CommitChanges();
   
   if(tgtObj.ObjectType == ObjectType.Hatch && srcObj.ObjectType == ObjectType.Hatch)
   {
       var srcHatch = srcObjRef.Hatch();
       var tgtHatch = tgtItem.Object() as HatchObject;
       tgtHatch.HatchGeometry.PatternIndex = srcHatch.PatternIndex;
       tgtHatch.HatchGeometry.PatternRotation = srcHatch.PatternRotation;
       tgtHatch.HatchGeometry.PatternScale = srcHatch.PatternScale;
       tgtHatch.CommitChanges();
   }

   if(tgtObj.ObjectType == ObjectType.Annotation && srcObj.ObjectType == ObjectType.Annotation)
       RhinoApp.RunScript(doc.RuntimeSerialNumber, "-_MatchAnnotation -_SelId " + tgtObj.Id.ToString() + " _Enter -_SelId " + srcObj.Id.ToString() + " _Enter", true);

   if(!opMPCopyAttrUserText && tgtObj.Attributes.HasUserData)
   {
       tgtObj.Attributes.UserData.Purge();
       tgtObj.CommitChanges();
   }
}

And offset:

// #! csharp
// AcadOffset.cs

using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;

var doc = RhinoDoc.ActiveDoc;
bool opCopyAttrUserText;

if(doc.RuntimeData.ContainsKey("opCopyAttrUserText"))
   opCopyAttrUserText = (doc.RuntimeData["opCopyAttrUserText"] == "On") ? true : false;
else
{
   doc.RuntimeData.Add("opCopyAttrUserText", "Off");
   opCopyAttrUserText = false;
}

var go = new Rhino.Input.Custom.GetObject();
go.SetCommandPrompt("Select curve to offset");
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;

var copyAttrUserTextOption = new Rhino.Input.Custom.OptionToggle(opCopyAttrUserText, "Off", "On");
go.AddOptionToggle("CopyAttributeUserText", ref copyAttrUserTextOption);

for(;;)
{
   var rc = go.GetMultiple(1,1);
   if(go.CommandResult() != Result.Success || null == go.Object(0))
      return;
   else if (rc == Rhino.Input.GetResult.Option)
   {
       opCopyAttrUserText = copyAttrUserTextOption.CurrentValue;
       doc.RuntimeData["opCopyAttrUserText"] = opCopyAttrUserText ? "On" : "Off";
       continue;
   }

   var objrefSource = go.Object(0);
   var crv = objrefSource.Curve();

   if(null == crv || crv.IsShort(RhinoMath.ZeroTolerance))
       return;

   doc.Objects.Select(objrefSource);
   RhinoApp.ExecuteCommand(RhinoDoc.ActiveDoc, "_Offset");
   doc.Objects.UnselectAll();

   var crvNew = doc.Objects.MostRecentObject();
   crvNew.Attributes = objrefSource.Object().Attributes;
   
   if(!opCopyAttrUserText && crvNew.Attributes.HasUserData)
        crvNew.Attributes.UserData.Purge();

   crvNew.CommitChanges();
}

2 Likes

RH-82678 is fixed in Rhino 8 Service Release 9

1 Like