#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2015
    Posts
    4
    Rep Power
    0

    Help Converting Python script to VB script


    Hello Guys
    Is there is a way to convert the attached python code to vb script?
    I have absolutely no idea of both codes but I need to have the code in VB if you please
    The code is about 1 page only
    Thanks in advance

    Code:
    KnifeTipOffset = 1.5
    CutDepth = -0.3
    SwivelAngle = 20
    DentLength = 0
    RetractEnable = 1
    RetractAngle = 20
    RetractDepth = -0.25
    
    
    app.log("KnifeTipOffset "+KnifeTipOffset.ToString())
    app.log("CutDepth       "+CutDepth.ToString())
    app.log("SwivelAngle    "+SwivelAngle.ToString())
    app.log("RetractEnable  "+RetractEnable.ToString())
    app.log("RetractAngle   "+RetractAngle.ToString())
    app.log("RetractDepth   "+RetractDepth.ToString())
    
    
    ####### MAIN LOOP #########################################
    
    CamBamUI.MainUI.UndoBuffer.AddUndoPoint("Undo Here")
    CamBamUI.MainUI.UndoBuffer.Add(doc.ActiveLayer.Entities)
    
    for ent in view.Selection:
      if ent.GetType().Name == "Polyline":
        xpoly = XPolyline(ent)
        app.log("**********************************************************")
        app.log("************************Polyline**************************")
        app.log("**********************************************************")
        app.log("Polyline:      "+ent.ID.ToString())
        seg = xpoly.FirstSegment
        poly = Polyline()
        SegNum = 1
    
      ######## Loop for each segment within the Polyline #########
        while seg is not None:
    
          P1X = seg.P1.X
          P1Y = seg.P1.Y
          P2X = seg.P2.X
          P2Y = seg.P2.Y
          V1 = seg.VNormal1.Normal().Normal().Normal()
          V2 = seg.VNormal2.Normal().Normal().Normal()
          VFirst = Vector2F(1,0)
          VLast = Vector2F(1,0)
    
      #### First Point is oriented to X-axis and calculate sweep/bulge to first segment
          if seg == xpoly.FirstSegment:
            CFirst = Point2F(P1X+KnifeTipOffset, P1Y)
            CFirstXP = Vector3F.CrossProduct(Vector3F(1,0,0),Vector3F(V1.X,V1.Y,0))
            CFirstDirection = Math.Sign(CFirstXP.Z)
            if CFirstDirection == 0:
              CFirstDirection = 1
            CFirstSweep = Math.Acos(round(Vector2F.DotProduct(VFirst,V1)/(VFirst.Length*V1.Length),10))
            CFirstB = Math.Tan(CFirstSweep/4)*CFirstDirection
    
            app.log("CFirst         "+CFirst.ToString())
            app.log("CFirstSweep    "+CFirstSweep.ToString())
            app.log("CFirstXP       "+CFirstXP.ToString())
            app.log("CFirstDirection"+CFirstDirection.ToString())
            app.log("CFirstB        "+CFirstB.ToString())
    
    
      #### Set the VN1 vector direction of the next segment
    
          if seg == xpoly.LastSegment:  
            VN1 = VLast    # vector VLast points toward +X after last segment
    
          else:
            VN1 = seg.NextSegment.VNormal1.Normal()
            VN1.Invert()
    
    
      #### Remaining Segments - Calculate Cut Points (C1,C2) and Cut Segment Bulge (C1B)
    
          C1 = Point2F(P1X+V1.X*KnifeTipOffset,P1Y+V1.Y*KnifeTipOffset)
    
          if seg.GetType().Name == "XPolySegLine":      
            C1B = 0
            C2 = Point2F(P2X+V2.X*KnifeTipOffset, P2Y+V2.Y*KnifeTipOffset)
    
          elif seg.GetType().Name == "XPolySegArc":
            C1B = Math.Tan(seg.Sweep/4)
            C2X = P2X+KnifeTipOffset/((1+(V2.Y/V2.X)**2)**.5)*Math.Sign(V2.X)
            C2Y = P2Y+(KnifeTipOffset*V2.Y/V2.X)/((1+(V2.Y/V2.X)**2)**.5)*Math.Sign(V2.X)
            C2 = Point2F(C2X,C2Y)
    
    
      #### Calculate Bulge (C2B) for the Sweep Path between segments
    
          VC2 = Vector2F(seg.P2,C2)  # vector from P2 to C2 used for calculating sweep path bulge
          C2XP = Vector3F.CrossProduct(Vector3F(VC2.X,VC2.Y,0),Vector3F(VN1.X,VN1.Y,0))
          C2Direction = Math.Sign(C2XP.Z)
          if C2Direction == 0:
            C2Direction = 1
          C2Sweep = Math.Acos(round(Vector2F.DotProduct(VC2,VN1)/(VC2.Length*VN1.Length),10))
          C2B = Math.Tan((C2Sweep)/4)*C2Direction
          C2Angle = C2Sweep*180/Math.PI
    
    
      #### Calculate CLast to orient the tool in the +X direction to prepare for additional segments
    
          CLast = Point2F(seg.P2.X+VLast.X*KnifeTipOffset, seg.P2.Y+VLast.Y*KnifeTipOffset)
    
    
      ######  End of Calculation Section
    
          app.log("******************Segment*******************")
          app.log("Segment        "+SegNum.ToString())
          app.log("P1             "+seg.P1.ToString())
          app.log("P2             "+seg.P2.ToString())
          app.log("V1             "+V1.ToString())
          app.log("V2             "+V2.ToString())
          app.log("V2X SIGN       "+Math.Sign(V2.X).ToString())
          app.log("V2Y SIGN       "+Math.Sign(V2.Y).ToString())
          app.log("C1             "+C1.ToString())
          app.log("C2             "+C2.ToString())
          app.log("C1B            "+C1B.ToString())
    	  app.log("VN1            "+VN1.ToString())
    	  app.log("VN1.Length     "+VN1.Length.ToString())
    	  app.log("VC2            "+VC2.ToString())
    	  app.log("VC2.Length     "+VC2.Length.ToString())
          app.log("C2Sweep        "+C2Sweep.ToString())
          app.log("C2B            "+C2B.ToString())
    
    
    ########################################################
    # Add points to path with depth logic###################
    ########################################################
    
          if seg == xpoly.FirstSegment:
            if RetractEnable == 1:
              poly.Add(CFirst.X, CFirst.Y, RetractDepth, CFirstB)
              poly.Add(C1.X, C1.Y, RetractDepth, 0)
            elif RetractEnable == 0:
              poly.Add(CFirst.X, CFirst.Y, CutDepth, CFirstB)
    
          if seg.Length > DentLength: # Ignore placement of short "Dent" segments
              poly.Add(C1.X, C1.Y, CutDepth, C1B)
    
          if C2Angle >= SwivelAngle:  # then do a swivel move
            if seg.Length > DentLength: # Ignore swivel segment for "Dents"
              if RetractEnable == 1:
                poly.Add(C2.X, C2.Y, CutDepth, 0)
                poly.Add(C2.X, C2.Y, RetractDepth, C2B)
              elif RetractEnable == 0:
                poly.Add(C2.X, C2.Y, CutDepth, C2B)
    
          else: # otherwise do not do a swivel move
            poly.Add(P2X+KnifeTipOffset*VN1.X, P2Y+KnifeTipOffset*VN1.Y, CutDepth, 0)
    
          if seg == xpoly.LastSegment:
            if RetractEnable == 1:
              poly.Add(CLast.X, CLast.Y, RetractDepth, 0)
            elif RetractEnable == 0:
              poly.Add(CLast.X, CLast.Y, CutDepth, 0)
    
          app.log("SwivelAngle    "+SwivelAngle.ToString())
          app.log("C2Angle        "+C2Angle.ToString())
    
    #### End of Main Loop #####################################
          SegNum += 1
          seg = seg.NextSegment
        doc.Add(poly)
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,888
    Rep Power
    509
    This could be a large task. In the statement

    poly.Add(C1.X, C1.Y, CutDepth, C1B)

    poly is the instance of a class and whomever makes this conversion would need to know about the class with particular detail about the Add method. Much easier if you just have the vb code execute a system call to run python and use the python program as is.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2015
    Posts
    4
    Rep Power
    0
    poly.Add

    Is that the only problem?
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,478
    Rep Power
    1875
    Originally posted by billt; Reply #47 on: July 29, 2014, 00:01:13 am

    I see your replies on this thread, but that was months ago.

    Have you spent all the intervening time trawling the net looking for python forums to do your work for you?

    Comments on this post

    • Will-O-The-Wisp agrees
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,888
    Rep Power
    509
    I'm just guessing you need someone familiar with the application area as well.
    Because of the "knife depth", "swivel angle" and cross products the program looks like it controls a numerical machine tool of some sort. You might need a new interface to the device.

    Dude/Dudette, come on, why would someone unfamiliar with the project know what

    CamBamUI.MainUI.UndoBuffer.AddUndoPoint("Undo Here")

    is supposed to do, or look like on the user interface.

    Comments on this post

    • Will-O-The-Wisp agrees
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2015
    Posts
    4
    Rep Power
    0
    Originally Posted by salem
    Originally posted by billt; Reply #47 on: July 29, 2014, 00:01:13 am

    I see your replies on this thread, but that was months ago.

    Have you spent all the intervening time trawling the net looking for python forums to do your work for you?
    Does it bother you that much to ask?
    I have already said that I have no idea of both codes
    I have already contacted the code author and he said he dont know anything about VB so calm down
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2015
    Posts
    4
    Rep Power
    0
    Originally Posted by b49P23TIvg
    I'm just guessing you need someone familiar with the application area as well.
    Because of the "knife depth", "swivel angle" and cross products the program looks like it controls a numerical machine tool of some sort. You might need a new interface to the device.

    Dude/Dudette, come on, why would someone unfamiliar with the project know what

    CamBamUI.MainUI.UndoBuffer.AddUndoPoint("Undo Here")

    is supposed to do, or look like on the user interface.
    Thank you, I will use the code as it is

IMN logo majestic logo threadwatch logo seochat tools logo