MoI discussion forum
MoI discussion forum

Full Version: Select objects

From: pixelhouse
20 Jan 2020   [#1]
Hello friends,

I'm searching for an script that can select small objects, to delete small things like screws, springs and washers.
I had an script for Cinema 4d that is written in Phyton, but it dosn't run in R19 and R 20....
This one was extrem helpfull and makes a fast workflow to clean up SW-models for visualisations.
In Solidworks itself it is not possible to delete small tings automaticly.
I'm not sure if its possible to select small things via a script about the volume or the size or the point-count.

Maybe there is such a script already?

Thank you for any Tips and ideas :)

Kind regards
Jörg
From: Frenchy Pilou (PILOU)
20 Jan 2020   [#2] In reply to [#1]
Change your values as you want! ;)

script: /* Select by length */ var min = 1.0, max = 5.0; var crvs = moi.geometryDatabase.getObjects().getCurves(); for ( var i = 0; i < crvs.length; ++i ) { var crv = crvs.item(i); var len = crv.getLength(); if ( len>= min && len <= max ) { crv.selected = true; } }

script: /* select biggest curve */ var curves = moi.geometryDatabase.getObjects().getCurves(); var maxlen = -1; var maxcrv = null; for ( var i = 0; i < curves.length; ++i ) { var crv = curves.item(i); if ( crv.hidden || crv.locked ) { continue; } var thislen = crv.getLength(); if ( thislen> maxlen ) { maxlen = thislen; maxcrv = crv; } } if ( maxcrv != null ) maxcrv.selected = true;

script: /* select smallest curve*/ var curves = moi.geometryDatabase.getObjects().getCurves(); var minlen = 1e100; var mincrv = null; for ( var i = 0; i < curves.length; ++i ) { var crv = curves.item(i); if ( crv.hidden || crv.locked ) { continue; } var thislen = crv.getLength(); if ( thislen < minlen ) { minlen = thislen; mincrv = crv; } } if ( mincrv != null ) mincrv.selected = true;
From: Michael Gibson
20 Jan 2020   [#3] In reply to [#1]
And a couple other ones here:
http://kyticka.webzdarma.cz/3d/moi/#SelectTiny

- Michael
From: pixelhouse
20 Jan 2020   [#4] In reply to [#2]
Hi Pilou,

thank you for your response :)
I have copied the script and add a short cut, but only curves will be selected.
There are some lines in the code with "curves" :) I need to select objects, no curves. I'm not confirm with scripting.

This script from Petr's MOI page seems to do this :)

script: /* Select objects smaller than the given size */ var size = 1.0; var objs = moi.geometryDatabase.getObjects(); for ( var i = 0; i < objs.length; ++i ) { var obj = objs.item(i); var bbox = obj.getBoundingBox(); if ( bbox.diagonalLength < size ) obj.selected = true; }

Thanks a lot :)
From: pixelhouse
20 Jan 2020   [#5] In reply to [#3]
Thank you Michael,

this script works fine :)
From: Frenchy Pilou (PILOU)
21 Jan 2020   [#6] In reply to [#4]
Seems you right...