Create Objects and then replace them with userinput
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I Would like to create a drawing from vb.net, and when it is drawn, i would like to move it to the place the user wants it to be in the drawing using a ghost-image on the mouse cursus
... i cannot get it to work, my head explodes..(rather new at .net, used to vba)
this is what i have at this point:
I have a drawing, in this examples just 2 rectangles, which are drawn by vb.net, and put in an arraylist.
this arraylist has to be dragged to another location in the drawing by the user.
I want to get an objectcollection in a selectionset (or if anyone has a better idea??)
kind regards Wouter de Haan
----
Public Class Drag
Dim OriPunt AsPoint3d = Point3d.Origin
<Autodesk.AutoCAD.Runtime.CommandMethod("MD")> PublicSub MoveDrawing()
'--- draw 2 rectangles and add them to a arraylist
Dim GroepBoven AsNewArrayList
GroepBoven.Add(Cad_Teken.Rechthoek(10, 10, 100, 100)) '(result is an object)
GroepBoven.Add(Cad_Teken.Rechthoek(20, 50, 150, 150))
ModelspaceAdd(GroepBoven)
EndSub
Sub DragSelection(ByVal Collectie AsObjectIdCollection)
???
Dim ss As SelectionSet = SelectionSet.FromObjectIds(Collectie)
ForEach id As ObjectId InCollectie
ss.add = SelectionSet.FromObjectIds(id)
Next
????
DragSelection(ss)
EndSub
Sub DragSelection(ByVal Objektid() AsObjectId)
' just drag one object (works)
Dim ss AsSelectionSet = SelectionSet.FromObjectIds(Objektid)
DragSelection(ss)
EndSub
Sub DragSelection(ByVal Selectieset AsSelectionSet)
Dim doc AsDocument = Application.DocumentManager.MdiActiveDocument
Dim db AsDatabase = doc.Database
Dim ed AsEditor = doc.Editor
Using tr AsTransaction = db.TransactionManager.StartTransaction
'---set de selectieset
ed.SetImpliedSelection(Selectieset)
'---bepaal bounding box en daarmee linkeronderhoek van selectie: NOG NIET GEDAAN
OriPunt = NewPoint3d(100, 100, 100)
'---Ask new location
Dim ppr As PromptPointResult = ed.Drag(Selectieset, vbLf & "Selecteer nieuwe locatie: ", New DragCallback(AddressOfMyDragCallback))
If (ppr.Status = PromptStatus.OK) Then
'--- Bepaal de translatiematrix
Dim mat AsMatrix3d = Matrix3d.Displacement(OriPunt.GetVectorTo(ppr.Value))
Dim currentSpace As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
'--- Verplaats alle onderdelen in de selectieset
ForEach selectedObj As SelectedObject InSelectieset
Dim selectedEntity As Entity = DirectCast(tr.GetObject(selectedObj.ObjectId, OpenMode.ForWrite), Entity)
selectedEntity.TransformBy(mat)
Next'--- Bevestig de transactie
tr.Commit()
EndIf
EndUsing
EndSub
PrivateFunction MyDragCallback(ByVal pt As Point3d, ByRef mat As Matrix3d) AsSamplerStatus
If (OriPunt = pt) Then'--- Als er geen wijziging is gemaakt, dit meldenReturnSamplerStatus.NoChange
Else'---Anders de transformatiematrix maken voor de verplaatsing
mat = Matrix3d.Displacement(OriPunt.GetVectorTo(pt))
EndIf
ReturnSamplerStatus.OK
End Function
End Class