Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from FreeCADGui import Selection
- from FreeCAD import Base
- from PyQt4 import QtCore
- import DraftGeomUtils
- def extend(line1,line2,nearpoint):
- '''extends a Draft Line to another line -very similar to extend command in AutoCAD and it's clones '''
- edge1=line1.Object.Shape.Edges[0]
- edge2=line2.Object.Shape.Edges[0]
- #boundary =edge1,line to extend = edge2,nearpoint catches nearest vertex on line to extend
- #find the intersection point first
- intpt = DraftGeomUtils.findIntersection(edge1,edge2,True,True)
- #find closest end point of line to extend
- closestpointindex = DraftGeomUtils.findClosest(nearpoint,line2.Object.Points)
- #extend the line from the closest point
- if closestpointindex==0:
- line2.Object.Start = ( intpt[0].x,intpt[0].y,intpt[0].z)
- else:
- line2.Object.End = ( intpt[0].x,intpt[0].y,intpt[0].z)
- #selection stuff
- class SelObserver:
- selected=False
- def addSelection(self, doc, object, sub, point):
- self.selected=True
- self.point=point
- def QtWait(ms):
- "QtWait(ms) Wait some time, leaving QT do its job."
- timer=QtCore.QTimer()
- timer.setSingleShot(True)
- loop=QtCore.QEventLoop()
- QtCore.QObject.connect(timer,QtCore.SIGNAL("timeout()"),loop,QtCore.SLOT("quit()"))
- timer.start(ms)
- loop.exec_(QtCore.QEventLoop.AllEvents)
- def wait4sel(gate):
- "wait4sel('gate') Wait for a selection filtered by the gate and return the clicked point"
- so=SelObserver()
- if (gate !=""):
- Selection.addSelectionGate(gate)
- Selection.addObserver(so)
- while (not so.selected):
- QtWait(100)
- Selection.removeSelectionGate()
- Selection.removeObserver(so)
- return so.point
- Msg("Select boundary Edges\r\n")
- pt=wait4sel("SELECT Part::Feature SUBELEMENT Edge")
- theObject=Gui.Selection.getSelectionEx()[0]
- Msg("Select line to extend\r\n")
- pt2=wait4sel("SELECT Part::Feature SUBELEMENT Edge")
- theObject2=Gui.Selection.getSelectionEx()[0]
- extend(theObject,theObject2,Base.Vector(pt2))
- App.activeDocument().recompute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement