Author Topic: Script help: Finding and Moving Points , resizing rectangles  (Read 197 times)

Offline jimmer

  • Storm Trooper
  • ***
  • Posts: 128
    • View Profile
Re: Script help: Finding and Moving Points , resizing rectangles
« Reply #15 on: July 18, 2021, 13:02:33 pm »

For completeness:

Here is my vbs script for resizing my rectangles

Quote
sub main

    dim message as string
    dim ent as Entity
    dim polyrect as PolyRectangle

    app.Clearlog()

        'scan selected entities
        for each ent in view.SelectedEntities
           
            if (typeof ent is PolyRectangle)
                polyrect = ent   
                if (polyrect.Width= 596.0)
                    polyrect.Width= 580.0
                    polyrect.Transform.Translate(8, 0, 0)
                    polyrect.update
                end if
                if (polyrect.Width= 595.0)
                    polyrect.Width= 579.0
                    polyrect.Transform.Translate(8, 0, 0)
                    polyrect.update
                end if
                if (polyrect.Width= 590.0)
                    polyrect.Width= 574.0
                    polyrect.Transform.Translate(8, 0, 0)
                    polyrect.update
                end if

            end if   
               
        next
       
        View.RefreshView()

end sub
       
Cambam. Mach3. USB motion controller. 1800x950 ballscrew router, vacuum bed, 3kW spindle.

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6489
    • View Profile
    • Cambam V1.0 French Doc
Re: Script help: Finding and Moving Points , resizing rectangles
« Reply #16 on: July 18, 2021, 21:45:22 pm »
Hello

Quote
The pointlists were disappearing. This time I worked it out (guessed it) myself. I think plist.points = plist2.points establishes equivalence or whatever it's called. So I did the transfer item by item.

Ah yes sorry, we need a new point array instead of using the one attached to plist2, because when we clear() the plist2, we also clear plist array because its the same array for both ...

this statement can solve the problem I think, the plist2 array is cloned, then the clone is linked to plist

plist.Points = plist2.Points.Clone

and in addition, on my previous code it is not at the right place in the loop.

this one sames to works on a multi selection

Code: [Select]
sub main

    dim message as string
    dim ent as Entity
    dim polyrect as PolyRectangle
    dim plist as PointList
    dim plist2 as pointlist = new pointlist 'temp pointlist
    dim pt as point3F

    app.Clearlog()

        'scan selected entities

        for each ent in view.SelectedEntities   
           
            if (typeof ent is PointList)
                plist = ent
                for each pt in plist.Points
                    if (pt.X > 290.99 and pt.X < 291.01)
                        message="pt.X="+formatnumber(pt.X,4)
                        'msgbox (message,0,"boxtitle")
                        plist2.add(283.0, pt.y, pt.z)
                    else
                        plist2.add(pt)'no change
                    end if
                next
            end if

            plist.points = plist2.points.clone 'clone the point array of plist2 and link the clone  to plist
            plist.update       
 
        next
       
        view.RefreshView()

end sub


++
David
« Last Edit: July 18, 2021, 22:05:39 pm by dh42 »