Quantcast
Channel: Rhino Developer - McNeel Forum
Viewing all 8686 articles
Browse latest View live

TreeGridView doesn't update

$
0
0

@jessen.ch wrote:

I have a TreeGridView defined like this:

        private void GenerateGridViewLayout()
        {
            gridviewlayout = new TreeGridView
            {
                DataStore = MyComponent
                
            };
            gridviewlayout.Columns.Add(new GridColumn { DataCell = new TextBoxCell("TreeItemName"), HeaderText = "Name", AutoSize = true, Width = 150, Resizable = true, Editable = false });
            gridviewlayout.Columns.Add(new GridColumn { DataCell = new TextBoxCell("TreeItemType"), HeaderText = "Type", AutoSize = true, Width = 110, Resizable = true, Editable = false });
            gridviewlayout.Columns.Add(new GridColumn { DataCell = new TextBoxCell("TreeItemDescription"), HeaderText = "Description", AutoSize = true, Resizable = true, Editable = false });
        }

Whereas MyComponent is a type of Component that implements these interfaces:

class Component : ITreeGridItem, ITreeGridStore<Component>, INotifyPropertyChanged, INotifyCollectionChanged
{

        /// ===================
        /// some other implementations
        /// ===================

        [Browsable(false)]
        public event PropertyChangedEventHandler PropertyChanged;
        
        [Browsable(false)]
        internal void NotifyPropertyChanged([CallerMemberName] string propertyName = null)  
        {  
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        [Browsable(false)]
        public event NotifyCollectionChangedEventHandler CollectionChanged;

        internal void NotifyCollectionChanged()
        {
            CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }

        [Browsable(false)]
        bool ITreeItem<ITreeGridItem>.Expanded { get; set; }

        [Browsable(false)]
        bool ITreeItem<ITreeGridItem>.Expandable
        {
            get { return Children.Any(); }
        }

        [Browsable(false)]
        public IEnumerable<Component> Children
        {
            get
            {
                return Component.AllComponents.Where(c => c.Parent == this);
            }
        }

        [Browsable(false)]
        ITreeGridItem ITreeItem<ITreeGridItem>.Parent  {  get;   set;  }


   
        [Browsable(false)]
        int IDataStore<Component>.Count
        {
            get
            {
                return Children.Count();
            }
        }


        Entity IDataStore<Component>.this[int index] => Children.ElementAt(index);

}

When I add or delete an Obect in Rhino, I fire MyComponent.NotifyCollectionChanged() event. But oddly the eventhandler ColletionChanged is null, meaning the TreeGridView is not subscribing to this event, thus it doesn’t update the view.

What’s wrong with my implementation?

Thanks in advance,
Chen

Environment: Windows 10 Pro 1903, Rhino Version 6 SR20(6.20.19322.20361, 11/18/2019), Eto version 2.5.0.0

Posts: 1

Participants: 1

Read full topic


Eto block width

$
0
0

@dick.lelyveld wrote:

Trying to make a form using the Eto framework in Python:


(Please don’t mind the colors…, these are only there two differentiate between the two blocks.)

It exists of two blocks, the first narrower then the second.
The first block has a label and a combobox.
The second has a textarea over the whole width, and below that a button (‘Export to…’) aligned to the right of that.

I cannot get the widths correct.

  1. Is it even possible to make blocks of a different width?
  2. Can I set the width of an element? (Like buttons.)

(A not so important question: can I color the background of blocks?)

Thanks!

My code so far:

import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms

class MyDialog(forms.Dialog):

    def __init__(self):

        self.Title = 'My Dialog'
        self.Padding = drawing.Padding(10)
        self.Resizable = False

        self.labelKeys = forms.Label(Text = 'ProdRef:\nProduct:\nOndermeubel:')
        self.labelKeys.Size = drawing.Size(-1,-1)
        self.labelValues = forms.Label(Text = 'Modulo 2 Kast\nOndermeubel\nModulo 2')
        self.checkLayers = forms.CheckBox(Text = ' from layers')
        self.checkLayers.Checked = True

        self.labelProps = forms.Label(Text = 'Properties from ')
        self.comboProps = forms.ComboBox()
        self.comboProps.DataStore = ['Layers', 'Object info']
        self.comboProps.SelectedIndex = 0

        self.textareaResult= forms.TextArea()
        self.textareaResult.Size = drawing.Size(770, 400)

        self.exportButton = forms.Button(Text = 'Export to ...')

        layout = forms.DynamicLayout()
        layout.DefaultSpacing = drawing.Size(5, 5)
        layout.Padding = drawing.Padding(10)

        layout.BeginVertical()
        layout.AddRow(self.labelKeys, self.labelValues)
        layout.AddRow(None, self.checkLayers)
        layout.EndVertical()

        layout.BeginVertical()
        layout.AddRow(self.labelProps, self.comboProps)
        layout.EndVertical()

        layout.BeginVertical()
        layout.AddRow(self.textareaResult)
        layout.AddRow(self.exportButton)
        layout.EndVertical()

        self.Content = layout

def TestMyDialog():
    dialog = MyDialog()
    dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

if __name__ == "__main__":
    TestMyDialog()

Posts: 1

Participants: 1

Read full topic

Finding truly outer and inner trims of brep

$
0
0

@Willem wrote:

Hi,

I’m about to write a python/RhinoCommon method to find inner and outer trims of a polysurface-brep.
The issue I need to solve is that Brep.DuplicateNakedEdgeCurves() is not sufficient in that it categorizes inner trims that run over multiple faces as outer naked edges:

Before I begin I’d like to ask if there is an existing way to identify all circles in this example as inner trims. Or if anybody has already solved this and likes to share.

Thanks
-Willem

Posts: 1

Participants: 1

Read full topic

Brep.Repair() running forever

$
0
0

@Willem wrote:

Hi,

I have brep that will not pass running Brep.Repair()
To replicate run the below python script on the attached file.

import rhinoscriptsyntax as rs
id = rs.AllObjects()[0]
brep = rs.coercebrep(id)
brep.Repair(0.01)

no_repair_plate.3dm (90.4 KB)

EDIT: tracked this down a single face
no_repair_face.3dm (52.9 KB)

Any clues on what’s happening?

Thanks
-Willem

Posts: 1

Participants: 1

Read full topic

Eto combobox in gridview (Python)

$
0
0

@dick.lelyveld wrote:

Trying to show a combobox in a gridview:

import Eto.Drawing as drawing
import Eto.Forms as forms

form = forms.Dialog()
form.Title = "test combobox in gridview"
form.ClientSize = drawing.Size(800, 600)
form.Resizable = False

comboMaterialType = forms.ComboBox(DataStore = ['Wood', 'Plastic'], SelectedIndex = 0)

dataStoreRow1 = ['Surface 01: Front_Planes', comboMaterialType]
dataStoreRow2 = ['Surface 02: Front_Edges', comboMaterialType]

gridOption1 = forms.GridView()
gridOption1.ShowHeader = False
gridOption1.DataStore = (dataStoreRow1, dataStoreRow2)
gridOption1.Columns.Add(forms.GridColumn(Editable = False, DataCell = forms.TextBoxCell(0)))
gridOption1.Columns.Add(forms.GridColumn(Editable = True, DataCell = forms.ComboBoxCell(1)))

layout = forms.DynamicLayout(DefaultSpacing = drawing.Size(5, 5), Padding = drawing.Padding(10))
layout.AddRow(gridOption1)

form.Content = layout
form.ShowModal()

The combobox is there but shows empty. You don’t see it immediately because the content is not shown.
When you click the combobox the first time (just behind the text), you have to click it a second time to see it’s a dropdown and a third time to actually see the dropdown list, which still shows empty:

eto_empty_combobox

What am I doing wrong?

PS: it’s a pity the documentation about Eto is so fragmented and in different languages. As I am not aquainted with C++ or C#, I can’t understand the code or translate it to Python …

Posts: 1

Participants: 1

Read full topic

RhinoScript material methods are mostly useless / obsolete

$
0
0

@Jarek wrote:

Hi @Dale,

You are probably aware of this but most of the RhinoScript methods that deal with material modifications are not working properly with current Rhino 6 materials. Even though some methods “seem” to work, it is not being retained.

Example: make a box, assign custom material to it.
Run this script:

    Dim o : o = Rhino.GetObject()
    Dim i: i = Rhino.ObjectMaterialIndex(o)
    Call Rhino.MaterialColor(i, vbRed)

It will change the color of the object to red. Ok, but not in Material Editor, plus once you save and re-open the file, the change is not remembered. I was recently trying to batch-change materials to use different folder for material texture maps, and same happens - the change is not retained. There are probably more examples I could come up with but the root of the “problem” must be the same - which is how materials are being coded in Rhino now vs. how the old RhinoScript methods are trying to handle them.

I can get things done via using RhinoScript RDK methods but it is much more cryptic, even though it offers access to many more attributes than RhinoScript methods.
But in general it should be noted that these don’t work anymore and I would suggest removing them from RhinoScript, or better yet, making them work with the new material system.

Many thanks,

–jarek

Posts: 1

Participants: 1

Read full topic

C++ code is rewritten as python code

Multi-threading C# PointCloud dist search

$
0
0

@Petras_Vestartas wrote:

Hi,

I have no experience in multi-threading, but would like to ask how to turn this for loop distance search to a plane into a multi-threaded loop using C#.

Also any advice how to make this search quicker would be great.

  public PointCloud Section(PointCloud cloud, Rhino.Geometry.Plane y,  double tol = 0.5) {
      double[] eq = y.GetPlaneEquation();
      double denom = 1 / Math.Sqrt(eq[0] * eq[0] + eq[1] * eq[1] + eq[2] * eq[2]);


      PointCloud cloudSection = new PointCloud();

      foreach (PointCloudItem it in cloud) {

        if (Math.Abs(FastPlaneToPt(denom, eq[0], eq[1], eq[2], eq[3], it.Location)) <= tol) {
          cloudSection.Add(it.Location);
        }

      }


      return cloudSection;
    }

Posts: 1

Participants: 1

Read full topic


Rhino v5 plugin in conflict with Rhino6 plugin

$
0
0

@marton.parlagh wrote:

My problem is…

We have a plugin version which works with Rhino 5 MacOSX.
And a new one which works with Rhino 6 MacOSX.

As far as I know both should be installed into the same folder:
“~/Library/Application Support/McNeel/Rhinoceros/MacPlugIns/”

But in this case these two are in conflict?

Is there a simple solution for this? (if I don’t want to rename the plugins…)

Márton

Posts: 1

Participants: 1

Read full topic

How transform CRhinoPhantomObject

$
0
0

@ceruti wrote:

Hello,
I have just added a CRhinoPhantomObject to a document using the following code:

in_doc.AddObject(phantomObject);

It there a way to move this object several times but starting always from the original position?
I would avoid to move always my object to the original position (using the previous matrix inverse) and then move it to the new position (in order to avoid cumulative errors after thousands of movements).
I would also avoid to remove and add the object each time if it is possible.

Thanx,
Matteo

Posts: 1

Participants: 1

Read full topic

Failing MergeAllFaces

$
0
0

@Willem wrote:

Hi (@rajaa I suppose)

The brep in the attached file failed a Brep.MergeCoplanarFaces.
The command MergeAllFaces fails as well.

error_mergeallfaces.3dm (67.3 KB)

I know it’s a nasty input yet I suppose you might want to check this for debugging.

Thanks
-Willem

Posts: 1

Participants: 1

Read full topic

Unable to add BRep object to Doc

$
0
0

@software_comas wrote:

Hi!
I’m working on a command that let user choose an existsing BRrep, duplicates it, transform it and, finally, add the duplicated and transformed BRep to the active RhinoDoc.
It used to work fine… Since I’ve found a document containing BReps my command doesn’t work with.
I mean… I can duplicate and transform BReps but I can’t add them to the active RhinoDoc.
Every time I try to do it, using RhinoDoc.Objects.Add(brepGeometry), i get an empty object ID as a result.
Of course i could add those objects to the doc (no locked layers ecc…).
The only thing that looks strange to me is that those BRep objects has their “IsValid” flag set to false.
Do you think this could be the problem?
What does it means to have the “IsValid” flag set to false?
Is there a way to make those objects “valid”?

PS Also Rhino “object details” window tells me that objects are not valid but I’m able to duplicate and transform them using Rhino interface.
Thanks a lot, guys! :slight_smile:

Posts: 2

Participants: 1

Read full topic

Number packing with C#

$
0
0

@daniel.depoe wrote:

Hello,

I’d like to pack an array of integers (which I’m calling ‘children’) into another integer (the ‘host’). The integers can be repeated. The goal is to pack as few integers into the host as possible.

The desired output is:

  1. an array of numbers outputting the number of times each ‘child’ integer has been ‘packed’ into the ‘host’ - the packCount
  2. an array of numbers outputting the remainders (modulos) after each ‘best’ integer has been ‘packed’ - the remainders

I have posted some code below, and the results I’m getting now. Is there a better way to achieve this in C#? I know that this doesn’t appear to have a Rhino application at first glance, but this is the beginning of a panelization routine I’m working towards.

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
        int host = 27;
        var children = new RhinoList<int> { 32, 28, 7, 2, 1 };

        RhinoApp.WriteLine("Host: {0}", host);
        RhinoApp.WriteLine("Children: [{0}]", string.Join(", ", children));

        int x = 0;
        int y = 0;

        int j = 0;
        int k = 0;

        var packCount = new RhinoList<int>();
        var remainder = new RhinoList<int>();

        //clear children greater than host and add to lists

        for (var i = 0; i < children.Count; i++)
        {
            if (host < children[i])
            {
                packCount.Add(0);
                remainder.Add(0);
            }

        }

        //remove bad children
        children.RemoveRange(0, packCount.Count);

        //pack first child into host and add to list
        x = host % children[0];
        remainder.Add(x);

        y = (host - x) / children[0];
        packCount.Add(y);

        //pack remaining children into remainders and add to list

        for (var i = 1; i < children.Count; i++)

        {
            j = remainder.Last % children[i];
            k = (remainder.Last - j) / children[i];

            remainder.Add(j);
            packCount.Add(k);

        }

        //output results

        RhinoApp.WriteLine("Pack counts: [{0}]", string.Join(", ", packCount));

        RhinoApp.WriteLine("Remainders: [{0}]", string.Join(", ", remainder));

   

        return Result.Success;

Result:

Host: 27
Children: [32, 28, 7, 2, 1]
Pack counts: [0, 0, 3, 3, 0]
Remainders: [0, 0, 6, 0, 0]

Posts: 1

Participants: 1

Read full topic

Polygon Mesh Detailing Option

Can an Osnap be subtracted from a set in a Python script?

$
0
0

@DanBayn wrote:

What I would like to be able to do is take a “snapshot” of the current Osnap state (easy to do) and subtract one from the current set. For example, let’s say the user has End, Near, Point and Cen active when the script begins. But I want whatever they had active to stay active with the exception of Near. Let the script execute with Near turned off, then when the script ends, restore their Osnap state (that part is easy to do too).

The next user might have Near, Point and Mid enabled, and I want that state to exist with the exception of Near. Each user might have a different Osnap state, so that’s why forcing certain Osnaps isn’t the answer (I already do that, I’m trying to improve on that).

Hope this makes sense,

Dan

Posts: 2

Participants: 2

Read full topic


Undo when it sends to the default layer

$
0
0

@fatihylmz.1923 wrote:

Greetings to all,

In Rhino 6, I save the line to a layer. What is the reason for undoing the line and assigning it to the default layer?

Posts: 2

Participants: 2

Read full topic

Ho to focus rhino and select object like grasshopper set geometry

$
0
0

@akitohotta3 wrote:

-Rhinocommon, -C#,

Hi, I’m new to Rhino Developing.
How to select and get geometry from a windows-form button-click? The form takes RhinoDoc as an argument.
-public MainForm(RhinoDoc rd)

I want to implement interactive-user-operation like grasshopper’s “set one geometry”.

Thanks

Posts: 1

Participants: 1

Read full topic

Parallel version of "Mesh.ExplodeAtUnweldedEdges()"?

$
0
0

@RIL wrote:

For medical mesh segmentation the method ExplodeAtUnweldedEdges() is crucial to me (in combination with Unweld & Weld). Unfortunately this method is really slow on huge meshes. A 300.000 MeshFaces mesh takes 3.2 minutes on my 3.2/3.7Ghz i7 3039 machine. 3.2 seconds would be bearable…

So, is there any chance that this method could run in parallel? Or is there anything else I can do to speed it up? The source code can reveal if there’s some exponential stuff going on there, or whatever reason for it being so slow. Knowing why could give hints about how I could (perhaps) prepare my meshes to reduce the processing time. 3.2 minutes is way way off for my use case.

Any other approach to achieve a similar segmentation functionality?


[Edit] - I tried to split the 300.000 face mesh into two and disjoint them in parallel (just a simple Mesh[2] parallel loop) and reduced the time to 54sec. 2 x 54 sec = 1:52 min is a significant reduction from 3.2 minues (single mesh, single thread). This could be an indication, although not certain, that there’s some kind of O(N^2) phenomenon going on in the ExplodeAtUnweldedEdges() method. Anyone?

// Rolf

Posts: 2

Participants: 2

Read full topic

Get InstanceDefinition for selected object in BlockEditor

$
0
0

@dave_stasiuk wrote:

When using the Block Editor, I am listening to object selection events, and would like to be able to map back from selected objects to the InstanceDefinition it’s a part of. As I understand it, the Block Editor makes temporary copies of all of its objects, each with its own unique Guid (which is recreated each time the Block Editor is instantiated). So it seems that I can’t iterate over the document InstanceDefinitions to match based on Id. Is there any way to derive which InstanceDefinition is currently being edited?

Posts: 1

Participants: 1

Read full topic

Plugin properties

$
0
0

@jari123 wrote:

So I’ve been working on a plugin and wanted to change the circled logo. Is it possible to change it?
image

Posts: 1

Participants: 1

Read full topic

Viewing all 8686 articles
Browse latest View live


Latest Images