Author Topic: [VBS - C# - VB .net] parts of code (snippet)  (Read 74106 times)

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #15 on: March 09, 2015, 20:46:49 pm »
Hello,

Some discoveries  :)

Convert Drawing coordinates (drawing units) of a given point in Display coordinates (in pixels).

The 0,0 in XY for the display is in the upper left corner of the drawing window. the values returned are of Single type.

the 2 functions are in CamBam.UI.CADView

Public Function DrawingToScreen(ByVal pDrawing As Point3F) As PointF

convert a position in drawing units in it's position in pixels on the screen.

and

Public Function ScreenToDrawing(ByVal pScreen As PointF) As Point3F

convert a position in pixels on the screen in it's corresponding coordinates in the Drawing

An example for the first function

Code: [Select]
' give the corresponding screen coordinates of a point in the drawing


sub main

' the values returned in p_screen are the XY coordinates in pixels ; 0,0 in the upper left corner
' the values can be negative if the point in the drawing universe is out of the display

Dim p_screen as New PointF ' values are of Single type

' a Point3F that contain the data to convert in pixel, given in drawing units
Dim p_draw as New Point3F

' set the value for the drawing coordinate to the origine of the Cambam universe
' to test the results, you can pan the display to change the position of the XY cross then run the script
p_draw.x = 0
p_draw.y = 0
p_draw.z = 0

'return the position in pixels on the screen of the 0,0,0 position in drawing coordinates
p_screen = DrawingToScreen(p_draw)

app.log ("X screen: " & p_screen.x)
app.log ("Y screen: " & p_screen.y)
app.log ("")


end sub

++
David

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #16 on: March 09, 2015, 21:15:49 pm »
Thank you, David!  That's "one more arrow in the quiver."  (well, two, actually)

LLoyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4468
    • View Profile
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #17 on: March 09, 2015, 21:36:09 pm »
Yes, good one, Lloyd, maybe this allows the print plugin to output drawings to scale ?
Made in England

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #18 on: March 09, 2015, 21:49:03 pm »
Time to time, I take my lamp and I explore the dll .. and sometimes I find something ...  :o

Quote
Yes, good one, Lloyd, maybe this allows the print plugin to output drawings to scale ?

Yes, and also to do marks on the screen not dependent of the zoom factor, unit ... and of course to do a custom edit mode ...

In my resize line script I use a circle to show the start point, but depending of the zoom or mm/in settings, it is always too big or too small ...

The problem it's that I must change my screen ... the function returns "half of pixels"  ;D ;D

++
David

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #19 on: March 09, 2015, 23:33:08 pm »
Well... maybe not TO scale, but certainly "WITH a scale"! <G>

LLoyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #20 on: March 15, 2015, 21:25:08 pm »
Hello,

2 new experiments with EditMode and VB script

EntityMoveEditMode

Same thing that the move command ; the selected object(s) can be moved from a first clicked point to a second.

Select one or more entities and run the script.

Code: [Select]
' EntityMove - dh42

dim abortedit As Boolean, edit_finished as boolean

sub main

abortedit = false
edit_finished = false

Move_Entity()

app.log(abortedit)

end sub

sub Move_Entity()

        Dim edmode As New EntityMoveEditMode(CamBamUI.MainUI.ActiveView)

        edmode.DefaultValue = vbNull
        edmode.Prompt = "Move entity"
        AddHandler edmode.OnReturnOK, AddressOf point_clicked
        AddHandler edmode.OnReturnCancel, AddressOf point_clicked_clr

        CamBamUI.MainUI.ActiveView.SetEditMode(edmode)  'run the edit mode

do while edit_finished = false
System.Windows.Forms.Application.DoEvents()
loop

End sub

Sub point_clicked(ByVal sender As Object, ByVal e As EventArgs)

'        CamBamUI.MainUI.ActiveView.RepaintEditMode()
edit_finished = true

End Sub

Sub point_clicked_clr(ByVal sender As Object, ByVal e As EventArgs)
        'cancel used
        abortedit = True
edit_finished = true

End Sub



EntityDragEditMode

The entity to move (only one in this script) is taken by a given position (in pixel on the screen) and is dragged to a point that must be cliqued.

It remain a problem that I can't solve ; when the job ends, a rubber line stay attached to the mouse .. as for a rectangular selection ... I have spend a lot of time to try to remove it, with no success ...

If someone found the trick !!

Code: [Select]
' EntityDrag - dh42

dim edit_finished as boolean

sub main

dim ent as entity
Dim p_draw as New Point3F
dim p as pointF
dim pt as system.drawing.point 'the handle point for draging (in pixels)

'only one entity
if view.SelectedEntities.Length = 1 then

for each ent in view.SelectedEntities
p_draw = ent.GetCentroid() 'get centroid of the entity in current coordinates
next

else
app.log("no selection")
exit sub
end if


'return the position in pixels off the centroid of the selected entity

p = DrawingToScreen(p_draw)

'nedeed to convert PointF to system.drawing.point
pt.x = p.x
pt.y = p.y

' -----------------------------------------------

edit_finished = false

Move_Entity(pt)

'apply transformation after the entity has been moved.

if ent.ApplyTransformation() then
     ent.Transform = Matrix4x4F.Identity
end if

CamBamUI.MainUI.ActiveView.select(ent)
CamBamUI.MainUI.ActiveView.RefreshView()

app.log (" center XY drawing: " & p_draw.x & " - " & p_draw.y)
app.log (" center XY pixels: " & pt.x & " - " & pt.y)

end sub

sub Move_Entity(pt as system.drawing.point)

        Dim edmode As New EntityDragEditMode(CamBamUI.MainUI.ActiveView,pt)

        edmode.DefaultValue = vbNull
        edmode.Prompt = "Drag entity"

        AddHandler edmode.OnReturnOK, AddressOf point_clicked
        
        CamBamUI.MainUI.ActiveView.SetEditMode(edmode)  'run the edit mode

do while edit_finished = false 'wait for the edit mode is finished
System.Windows.Forms.Application.DoEvents()
loop

RemoveHandler edmode.OnReturnOK, AddressOf point_clicked

End sub

Sub point_clicked(ByVal sender As Object, ByVal e As EventArgs)

edit_finished = true

End Sub

++
David

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4468
    • View Profile
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #21 on: March 15, 2015, 21:56:16 pm »
It works fine for me, there is no rubber band
« Last Edit: March 15, 2015, 22:10:33 pm by EddyCurrent »
Made in England

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #22 on: March 15, 2015, 22:34:12 pm »
Hello Eddy,

I'll try it on 7 to view if the pb is the same.

++
David

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #23 on: March 15, 2015, 23:04:33 pm »

Same pb on both XP and W7 for me

http://screencast.com/t/ZtEIWey1El

++
David

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1345
    • View Profile
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #24 on: March 16, 2015, 02:23:49 am »
Hi David
The Drag edit mode invokes the rubber banding  (CB expects you to click a start point of the selection and an end point) your code is invoking the rubber banding at the end of your move routine and CB is expecting one more click to end the selection process.
Dave.

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #25 on: March 16, 2015, 21:23:39 pm »
Hello Dave,

Sorry, I don't understand ..  :-[

Quote
CB expects you to click a start point of the selection and an end point

It's for the EntityMoveEditMode that CB wait for a start and a end point.(the first code)

With the EntityDragEditMove, the selected shape is immediately "attached" to the mouse when the edit mode is run, and the shape is released with the first click and the editmode terminate  ..

Quote
your code is invoking the rubber banding at the end of your move routine

where ? ... I don't know yet how to invoke the rubber selection rectangle ; I have only invoking the EntityDragEditMove ..

Other strange thing ; why it works well for Eddy ...

I think I'll try with a plugin if the result is the same ...

++
David

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1345
    • View Profile
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #26 on: March 16, 2015, 23:14:02 pm »
Hi David
The clue is in the name of the method <DragEntityMode> This method expects a DragStarted event
and a DragEnded event So you invoke the method, click in the drawing area (this starts the
rubberbanding) then move the mouse to select some entity or entities  that you want, then click the
mouse again. The second click sends a DragComplete event. What your code is doing is invoking the
DragStarted event but not handling the DragCompleted event. See the methods below.
Hope this helps.
Dave.

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #27 on: March 16, 2015, 23:42:37 pm »
Ha ha .. OK. thanks ..

Is there a way to send myself a DragCompleted events to terminate the edit ? .. If not, I need another Editmode to do what I want ..

Where do you find the datas on the picture ? ... if I look on the entitydrageditmode on reflector I have very few info about this function ..(picture)

Good night ;)
++
David

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1345
    • View Profile
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #28 on: March 17, 2015, 00:26:25 am »
Hi David
I Haven't thought this through completely but I think you could use another CB method to do what you want
to achieve in this instance. As for exploring the methods I use ILspy Great free software that someone else here on the forum recommended,  And the object browser in VS2013 along with the debugger (To examine the data structures of the Entities) and have been known too resort to using Reflector and AutoDiagrammer as well.
If you have any questions About ILspy I'll be happy  to help.
Happy Coding.
Dave

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6141
    • View Profile
    • Cambam V1.0 French Doc
Re: [VBS - C# - VB .net] parts of code (snippet)
« Reply #29 on: March 17, 2015, 14:37:41 pm »
Hello Dave,

Thanks for the reply ; I'll take a look on ILspy ..

I think that I need to do my own editmode. The goal is to enhance my Dim&Arrows plugin.

What I want is:

click 2 point that are the ends of the line to measure, but unlike to the current version of the plugin, that puts the arrow ON the measured line, I want that, just after the 2 clicks, the arrow stays attached to the mouse to offset it from the line, and I want that the movement is contraint to a perpendicular to the line to measure, as on other CAD when I add a dimention ...

a lot of things to do ... and to learn ...

++
David