I want to find Line-Connection macro

Need help, or want to share a macro? Post here!
mrrclb48z
Posts: 27
Joined: Wed Feb 07, 2018 11:20 am

I want to find Line-Connection macro

Postby mrrclb48z » Sat May 12, 2018 4:00 pm

Line P0->P1->P2...->PN
Which of the 4 should be used? Please tell me the difference.
Thank you in advance and sorry for the bad english!
Partial Script:

Code: Select all

h=10
dx1=30*1
dx2=30*2
dx3=30*3
dx4=30*4
Connection1=[[dx1+0,0,h],  #0(1)
             [dx1+h,0,h],  #1(2)
             [dx1+h,h,h],  #2(3)
             [dx1+0,h,h],  #3(4)
             [dx1+0,0,0],  #4(5)
             [dx1+h,0,0],  #5(6)
             [dx1+h,h,0],  #6(7)
             [dx1+0,h,0]]  #7(8)
Connection2=[(dx2+0,0,h),  #0(1)
             (dx2+h,0,h),  #1(2)
             (dx2+h,h,h),  #2(3)
             (dx2+0,h,h),  #3(4)
             (dx2+0,0,0),  #4(5)
             (dx2+h,0,0),  #5(6)
             (dx2+h,h,0),  #6(7)
             (dx2+0,h,0)]  #7(8)
Connection3=([dx3+0,0,h],  #0(1)
             [dx3+h,0,h],  #1(2)
             [dx3+h,h,h],  #2(3)
             [dx3+0,h,h],  #3(4)
             [dx3+0,0,0],  #4(5)
             [dx3+h,0,0],  #5(6)
             [dx3+h,h,0],  #6(7)
             [dx3+0,h,0])  #7(8)
Connection4=((dx4+0,0,h),  #0(1)
             (dx4+h,0,h),  #1(2)
             (dx4+h,h,h),  #2(3)
             (dx4+0,h,h),  #3(4)
             (dx4+0,0,0),  #4(5)
             (dx4+h,0,0),  #5(6)
             (dx4+h,h,0),  #6(7)
             (dx4+0,h,0))  #7(8)
print(Connection1)
print(Connection2)
print(Connection3)
print(Connection4)
#[[30, 0, 10], [40, 0, 10], [40, 10, 10], [30, 10, 10], [30, 0, 0], [40, 0, 0], [40, 10, 0], [30, 10, 0]]
#[(60, 0, 10), (70, 0, 10), (70, 10, 10), (60, 10, 10), (60, 0, 0), (70, 0, 0), (70, 10, 0), (60, 10, 0)]
#([90, 0, 10], [100, 0, 10], [100, 10, 10], [90, 10, 10], [90, 0, 0], [100, 0, 0], [100, 10, 0], [90, 10, 0])
#((120, 0, 10), (130, 0, 10), (130, 10, 10), (120, 10, 10), (120, 0, 0), (130, 0, 0), (130, 10, 0), (120, 10, 0))
(Sample) MacroRecording
full Script:

Code: Select all

import FreeCAD
import DraftTools
import Draft
points=[FreeCAD.Vector(-2.46063542366,-0.902365505695,1.0),FreeCAD.Vector(-0.0357767827809,0.743358254433,2.0)]
Draft.makeWire(points,closed=False,face=True,support=None)
points=[FreeCAD.Vector(-0.0357767827809,0.743358254433,2.0),FreeCAD.Vector(-6.0,6.0,0.0)]
Draft.makeWire(points,closed=False,face=True,support=None)
points=[FreeCAD.Vector(-6.0,6.0,0.0),FreeCAD.Vector(2.58766530498,8.42483132716,0.0)]
Draft.makeWire(points,closed=False,face=True,support=None)
SchmilBlick
Posts: 26
Joined: Fri Jan 09, 2015 8:31 pm
Location: France

Re: I want to find Line-Connection macro

Postby SchmilBlick » Sat May 12, 2018 4:31 pm

I had the same question while coding some scripts. I found this explanation: tuple vs list https://stackoverflow.com/questions/170 ... o-use-each

tuple uses () when list uses []. With a list you can use the methods append et remove to add or remove points to your connections for example.
Ubuntu 16.04 LTS 64bits - FreeCAD daily-build - FreeCAD 0.17