Hey everyone. Just joined the Snap Community. I really like the simple functionality it offers but I encountered my first Problem. I have some basic knowledge in Visual Basic but still need to get into it.
To my Problem: I want to have the later user draw a rectangle before starting the Programm. When he starts the Programm there will Pop up a window asking the user to select two orthogonal lines. I wanna use those lines later to calculate two direction vectors and also the lengths of the selected lines. Ive gotten so far that i created the Dialog but i cant seem to convert the SelectedObject type or NXObject type into a line so i can look at the length and direction. Im also asking myself how i can take out the selected lines of the Blockform class to use it for later purposes. This is how ive gotten so far. Any tips on the conversions or return of the desired objects ?
Imports Snap, Snap.Create, Snap.NX.ObjectTypes, Snap.Compute, Snap.UI.Input, Snap.NX
Imports Snap.UI
Public Class MyProgram
Public Shared Sub Main()
Dim menustart As New Squaremenu
menustart.Show()
End Sub
End Class
Public Class Squaremenu : Inherits Snap.UI.BlockForm
' Declarations of the blocks on a SnapBlockFormApplication1 dialog
Dim line1block As Snap.UI.Block.SelectObject
Dim line2block As Snap.UI.Block.SelectObject
' Constructor for a SnapBlockFormApplication1 dialog object
Public Sub New()
Me.Title = "Define your cubicle area geometry" ' Text to be shown in title bar of dialog
Me.Cue = "Select relevant points" ' Text to be shown in cue line
line1block = New Snap.UI.Block.SelectObject()
line1block.SetCurveFilter()
line1block.LabelString = "Select Line 1 (left)"
line2block = New Snap.UI.Block.SelectObject()
line2block.SetCurveFilter()
line2block.LabelString = " Select Line 2 (right)"
' Create addition blocks here, as you wish, and delete
' any of the ones above, if you don’t need them.
' Add all the blocks to the BlockForm
Me.AddBlocks(line1block, line2block)
End Sub
Public Shared Sub Main()
Dim myForm = New Squaremenu()
myForm.Show()
End Sub
Public Overrides Sub OnShow()
' Code for when dialog is displayed
End Sub
Public Overrides Sub OnOK()
'I know i must do the conversion and return here but the conversion doesnt work
Dim line1 as Line
line1 = line1block.SelectedObjects
End Sub
Public Overrides Sub OnApply()
End Sub
Public Overrides Sub OnCancel()
' Code for when user clicks Cancel
End Sub
Public Overrides Sub OnUpdate(changedBlock As Snap.UI.Block.General)
End Sub
End Class
Any help is much appreciated since there isnt alot of info on the web except for the Snap Guide.
Cheers
Re:
Hey everyone,
i solved it myself. I found a trick to use the wrap function of the curve class to get the object. and as for using the variables in further procedures i just created global variables. Code on how i solved my Problem below.
Public Overrides Sub OnOK()
Dim holder() As Snap.NX.NXObject
holder = Snap.NX.NXObject.Copy(line1block.SelectedObjects)
selectedline1 = Snap.NX.Curve.Wrap(holder(0).NXOpenTag)
holder = Snap.NX.NXObject.Copy(line2block.SelectedObjects)
selectedline2 = Snap.NX.Curve.Wrap(holder(0).NXOpenTag)
End Sub
Converting
You should set the selection filter to allow selection of lines only:
line1block.SetFilter(Snap.NX.ObjectTypes.Type.Line)
Then, to convert the selected object to a line:
Dim myLine As Snap.NX.Line = CType(selectedObjects(0), Snap.NX.Line)
There are two SNAP guides that you can refer to: the Getting Started guide and the Reference Guide.
thx
thx for your answer. i will try this way as well