public override void RemovedFromDocument(GH_Document document) { // let's be polite and pick up our garbage if (wormDoc != null) { wormDoc.Enabled = false; wormDoc.RemoveObject(wormCluster, false); wormDoc.Dispose(); wormDoc = null; } base.RemovedFromDocument(document); }
public static void ChangeObjects(IEnumerable <IGH_Param> items, IGH_Param newObject) { foreach (IGH_Param item in items) { //get the input it is connected to if (item.Recipients.Count == 0) { return; } var parrent = item.Recipients[0]; GH_DocumentIO docIO = new GH_DocumentIO(); docIO.Document = new GH_Document(); //get active GH doc GH_Document doc = item.OnPingDocument(); if (doc == null) { return; } if (docIO.Document == null) { return; } Component.AddObject(docIO, newObject, parrent, item.Attributes.Pivot); Component.MergeDocuments(docIO, doc, $"Create {newObject.Name}"); doc.RemoveObject(item, false); parrent.AddSource(newObject); } }
public override void AddedToDocument(GH_Document document) { Process.Start("https://github.com/woodsbagot/WombatGH/issues/new/choose"); base.AddedToDocument(document); GH_Document doc = Grasshopper.Instances.ActiveCanvas.Document; doc.RemoveObject(Attributes, true); }
public override void AddedToDocument(GH_Document document) { if (readFailed) { return; } if (SelectedConstructor != null) { base.AddedToDocument(document); if (Grasshopper.Instances.ActiveCanvas.Document != null) { var otherSchemaBuilders = Grasshopper.Instances.ActiveCanvas.Document.FindObjects(new List <string>() { Name }, 10000); foreach (var comp in otherSchemaBuilders) { if (comp is CreateSchemaObject scb) { if (scb.Seed == Seed) { Seed = GenerateSeed(); break; } } } } return; } _document = document; var dialog = new CreateSchemaObjectDialog(); dialog.Owner = Grasshopper.Instances.EtoDocumentEditor; var mouse = GH_Canvas.MousePosition; dialog.Location = new Eto.Drawing.Point((int)((mouse.X - 150) / dialog.Screen.LogicalPixelSize), (int)((mouse.Y - 150) / dialog.Screen.LogicalPixelSize)); //approx the dialog half-size dialog.ShowModal(); if (dialog.HasResult) { base.AddedToDocument(document); SwitchConstructor(dialog.model.SelectedItem.Tag as ConstructorInfo); } else { document.RemoveObject(this.Attributes, true); } }
private void SolutionCallback(GH_Document doc) { //read file, deserialize json, send variables out of the extracted class string jsonstring = File.ReadAllText(_path); ParamsData paramdata = new ParamsData(); paramdata = JsonConvert.DeserializeObject <ParamsData>(jsonstring); _n = paramdata.NumSliders; _dataIn = paramdata.SliderVals; _pointsdata = paramdata.Points; Random rnd = new Random(); List <IGH_DocumentObject> deletions = new List <IGH_DocumentObject>(); //list of objects to delete from grasshopper document List <OutputParam> outputParams = new List <OutputParam>(); //list of the slider grouping params and their output connections List <IGH_Param> PointRecvParams = new List <IGH_Param>(); //list of what the point param is connected to foreach (IGH_DocumentObject obj in GrasshopperDocument.Objects) { if (obj.NickName.StartsWith(_controlComponentName)) //the point and integer params i've created { deletions.Add(obj); IGH_Param tempParam = obj as IGH_Param; //cast obj into a param to locate sources and recipients if (tempParam.SourceCount > 0) { deletions.AddRange(tempParam.Sources); //add source sliders to deletions list } if (obj.NickName.StartsWith(_controlComponentName + "points")) { foreach (IGH_Param recip in tempParam.Recipients) { PointRecvParams.Add(recip); } } if (obj.NickName.StartsWith(_controlComponentName + "slids")) //the integer params { int ObjectIndex; Int32.TryParse(System.Text.RegularExpressions.Regex.Match(obj.NickName, @"(\d+)\z").Value, out ObjectIndex); //regex to extract index number from end of param name List <IGH_Param> receivingParams = new List <IGH_Param>(); foreach (IGH_Param recip in tempParam.Recipients) { receivingParams.Add(recip); } outputParams.Add(new OutputParam(ObjectIndex, receivingParams)); //put output param index and recipients into an object in a list } } } foreach (IGH_DocumentObject delobj in deletions) //delete the stuff { GrasshopperDocument.RemoveObject(delobj, false); } List <Grasshopper.Kernel.Parameters.Param_Integer> targetParam = new List <Grasshopper.Kernel.Parameters.Param_Integer>(); //holds the new output params as we build them //rename targetParam for (int index = 0; index < _n.Count; index++) //this loop runs once per slider bank //rename index { targetParam.Add(new Grasshopper.Kernel.Parameters.Param_Integer()); //create the new output param targetParam[index].NickName = _controlComponentName + "slids" + index; //assign the name to the output param including the index number GrasshopperDocument.AddObject(targetParam[index], false); if (index == 0) //put param in place { targetParam[index].Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 110); } else { _n[index] = _n[index] + _n[index - 1]; //aggregate list of number of sliders per bank to create slider index breakpoints targetParam[index].Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 110 + _n[index - 1] * 20 + index * 10); } if (outputParams.Exists(opar => opar.outParam == index)) //looks in the list of deleted output params and determines if one has the same index as the param being created { foreach (IGH_Param receivingParam in outputParams.Find(opar => opar.outParam == index).recvParams) { receivingParam.AddSource(targetParam[index]); //connects the new param to the old param stuff } } } Grasshopper.Kernel.Parameters.Param_Point pointsParam = new Grasshopper.Kernel.Parameters.Param_Point(); pointsParam.NickName = _controlComponentName + "points"; GrasshopperDocument.AddObject(pointsParam, false); pointsParam.Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 70); foreach (IGH_Param receivingParam in PointRecvParams) { receivingParam.AddSource(pointsParam); } pointsParam.SetPersistentData(_pointsdata.ToArray()); int Yoffset = -12; int CurrentParam = 0; for (int i = 0; i < _n[_n.Count - 1]; i++) { if (_n.Exists(x => x == i)) { Yoffset = Yoffset + 10; CurrentParam++; } //instantiate new slider Grasshopper.Kernel.Special.GH_NumberSlider slid = new Grasshopper.Kernel.Special.GH_NumberSlider(); slid.CreateAttributes(); //sets up default values, and makes sure your slider doesn't crash rhino //customise slider (position, ranges etc) //targetParam.Attributes.Bounds slid.Attributes.Pivot = new System.Drawing.PointF((float)targetParam[0].Attributes.Pivot.X - slid.Attributes.Bounds.Width - 70, (float)targetParam[0].Attributes.Pivot.Y + i * 20 + Yoffset); slid.Slider.Maximum = 100; slid.Slider.Minimum = 0; slid.Slider.DecimalPlaces = 0; // slid.SetSliderValue((decimal) (rnd.Next(-50, 51))); if (i + 1 > _dataIn.Count) { slid.SetSliderValue(_dataIn[_dataIn.Count - 1]); } else { slid.SetSliderValue(_dataIn[i]); } //Until now, the slider is a hypothetical object. // This command makes it 'real' and adds it to the canvas. GrasshopperDocument.AddObject(slid, false); //Connect the new slider to this component targetParam[CurrentParam].AddSource(slid); } }
public override void AddedToDocument(GH_Document document) { if (readFailed) return; // To ensure conversion strategy does not change, we record if the user has modified this schema tag and will keep it as is. // If not, schemaTag will be synchronised with the default value every time the document opens. if (!UserSetSchemaTag) UseSchemaTag = SpeckleGHSettings.UseSchemaTag; if (SelectedConstructor != null) { base.AddedToDocument(document); if (Grasshopper.Instances.ActiveCanvas.Document == null) return; var otherSchemaBuilders = Grasshopper.Instances.ActiveCanvas.Document.FindObjects(new List<string>() { Name }, 10000); foreach (var comp in otherSchemaBuilders) { if (!(comp is CreateSchemaObject scb)) continue; if (scb.Seed != Seed) continue; Seed = GenerateSeed(); break; } (Params.Output[0] as SpeckleBaseParam).UseSchemaTag = UseSchemaTag; (Params.Output[0] as SpeckleBaseParam).ExpirePreview(true); return; } _document = document; var dialog = new CreateSchemaObjectDialog(); dialog.Owner = Grasshopper.Instances.EtoDocumentEditor; var mouse = GH_Canvas.MousePosition; dialog.Location = new Eto.Drawing.Point((int)((mouse.X - 150) / dialog.Screen.LogicalPixelSize), (int)((mouse.Y - 150) / dialog.Screen.LogicalPixelSize)); //approx the dialog half-size dialog.ShowModal(); if (dialog.HasResult) { base.AddedToDocument(document); SwitchConstructor(dialog.model.SelectedItem.Tag as ConstructorInfo); Params.ParameterChanged += (sender, args) => { if (args.ParameterSide != GH_ParameterSide.Input) return; switch (args.OriginalArguments.Type) { case GH_ObjectEventType.NickName: // This means the user is typing characters, debounce until it stops for 400ms before expiring the solution. // Prevents UI from locking too soon while writing new names for inputs. args.Parameter.Name = args.Parameter.NickName; nicknameChangeDebounce.Debounce(400, (e) => ExpireSolution(true)); break; case GH_ObjectEventType.NickNameAccepted: args.Parameter.Name = args.Parameter.NickName; ExpireSolution(true); break; } }; } else { document.RemoveObject(Attributes, true); } }