For some reasons I need to add some extra points on the specify brep data structure,
even I hope these points could show in the rhino show window, and How to do?
Does anyone help me?
For some reasons I need to add some extra points on the specify brep data structure,
even I hope these points could show in the rhino show window, and How to do?
Does anyone help me?
Hi @jerry1,
I would add the points to the Brep as user data. Then I would create a conduit and look for Breps that contain your user data. When found, draw the points.
β Dale
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var rc = RhinoGet.GetOneObject("Brep", false, ObjectType.Brep, out var objRef);
if (rc != Result.Success || objRef == null) return rc;
var brep = objRef.Brep();
if (brep == null || !brep.IsValid) return Result.Failure;
rc = RhinoGet.GetPoint("Vertex to add", false, out var location);
if (rc != Result.Success) return rc;
brep.Vertices.Add(location, RhinoMath.UnsetValue);
doc.Objects.Replace(objRef, brep);
doc.Views.Redraw();
return Result.Success;
}
AddVertex.zip (94.0 KB)
Hi @Mahdiyar,
Add a pointt to Brep.Vertices
is not recommended. The vertex list of a Brep is reserved for Brep components, and it can be easily modified or purged during editing.
The most reliable way is what I described above.
β Dale
Hi Dale, I try to imitate the sample code C# and translate to vb.netβ¦in the following
but error occur in : face.UnderlyingSurface().UserData.Add(ud)
it appear : userdata must be a public class and have a parameterless constructor
and how to solve it ?
Public Class MyCustomData
Inherits Rhino.DocObjects.Custom.UserData
β
Public Property IntegerData As Integer
Public Property StringData As String
β
Public Sub New()
End Sub
β
Public Sub New(ByVal i As Integer, ByVal s As String)
IntegerData = i
StringData = s
End Sub
β
Public Overrides ReadOnly Property Description As String
Get
Return βSome Custom Propertiesβ
End Get
End Property
β
Public Overrides Function ToString() As String
Return String.Format(βinteger={0}, string={1}β, IntegerData, StringData)
End Function
β
Protected Overrides Sub OnDuplicate(ByVal source As Rhino.DocObjects.Custom.UserData)
Dim src As MyCustomData = TryCast(source, MyCustomData)
If src IsNot Nothing Then
IntegerData = src.IntegerData
StringData = src.StringData
End If
End Sub
'
Public Overrides ReadOnly Property ShouldWrite As Boolean
Get
If IntegerData > 0 AndAlso Not String.IsNullOrEmpty(StringData) Then Return True
Return False
End Get
End Property
'
Protected Overrides Function Read(ByVal archive As Rhino.FileIO.BinaryArchiveReader) As Boolean
Dim dict As Rhino.Collections.ArchivableDictionary = archive.ReadDictionary()
If dict.ContainsKey("IntegerData") AndAlso dict.ContainsKey("StringData") Then
IntegerData = CInt(dict("IntegerData"))
StringData = TryCast(dict("StringData"), String)
End If
Return True
End Function
'
Protected Overrides Function Write(ByVal archive As Rhino.FileIO.BinaryArchiveWriter) As Boolean
Dim dict = New Rhino.Collections.ArchivableDictionary(1, "MyCustomData")
dict.[Set]("IntegerData", IntegerData)
dict.[Set]("StringData", StringData)
archive.WriteDictionary(dict)
Return True
End Function
End Class
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim flag_1 As Boolean
Select_Entity_and_Give_Group_Name(11, βselect surfaceβ, flag_1)
If flag_1 = False Then
Exit Sub
End If
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Dim bp As Brep
For g = 0 To surf_base_num - 1
If surf_base(g).Object.ToString = βRhino.DocObjects.BrepObjectβ Then
bp = surf_base(g).Brep
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Dim face = surf_base(g).Face()
Dim ud = TryCast(face.UnderlyingSurface().UserData.Find(GetType(MyCustomData)), MyCustomData)
If ud Is Nothing Then
βNo user data found; create one and add it
Dim i As Integer = 0
ud = New MyCustomData(i, βThis is some textβ)
face.UnderlyingSurface().UserData.Add(ud)
Else
RhinoApp.WriteLine("{0} = {1}", ud.Description, ud)
End If
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
End If
Next
RhinoDoc.ActiveDoc.Views.Redraw()
End Sub
I find my Class MyCustomData has error β¦ and modify as follow, then the result is ok
but when I add β public pt as point3d in MyCustomData class
the point (0,0,0) is still not appear ??
Public Class MyCustomData
Inherits Rhino.DocObjects.Custom.UserData
Public pt As Point3d
'
Public Property IntegerData As Integer
Get
End Get
Set(value As Integer)
End Set
End Property
Public Property StringData As String
Get
End Get
Set(value As String)
End Set
End Property
' Your UserData class must have a public parameterless constructor
Public Sub New()
MyBase.New()
End Sub
'
Public Sub New(ByVal i As Integer, ByVal s As String)
MyBase.New()
IntegerData = i
StringData = s
End Sub
'
Public Overrides ReadOnly Property Description As String
Get
Return "Some Custom Properties"
End Get
End Property
'
Public Overrides Function ToString() As String
Return String.Format("integer={0}, string={1}", IntegerData, StringData)
End Function
'
Protected Overrides Sub OnDuplicate(ByVal source As Rhino.DocObjects.Custom.UserData)
Dim src As MyCustomData = TryCast(source, MyCustomData)
If src IsNot Nothing Then
IntegerData = src.IntegerData
StringData = src.StringData
End If
End Sub
'
Public Overrides ReadOnly Property ShouldWrite As Boolean
Get
If IntegerData > 0 AndAlso Not String.IsNullOrEmpty(StringData) Then Return True
Return False
End Get
End Property
'
Protected Overrides Function Read(ByVal archive As Rhino.FileIO.BinaryArchiveReader) As Boolean
Dim dict As Rhino.Collections.ArchivableDictionary = archive.ReadDictionary()
If dict.ContainsKey("IntegerData") AndAlso dict.ContainsKey("StringData") Then
IntegerData = CInt(dict("IntegerData"))
StringData = TryCast(dict("StringData"), String)
End If
Return True
End Function
'
Protected Overrides Function Write(ByVal archive As Rhino.FileIO.BinaryArchiveWriter) As Boolean
Dim dict = New Rhino.Collections.ArchivableDictionary(1, "MyCustomData")
dict.[Set]("IntegerData", IntegerData)
dict.[Set]("StringData", StringData)
archive.WriteDictionary(dict)
Return True
End Function
End Class
Hi Dale,
I know your method, but when found, draw the points, and are these points independent? or rely on this Brep? I need these points rely on the brep.