Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hello,i want to build a csg tree model,but when i try to create a new intersection, it intersect with all existing models.
here is my code:
def generate_primitive(rootComp, control_points, point_weights, height, three_points, flag):
sketches = rootComp.sketches
xyPlane = rootComp.xYConstructionPlane
planes = rootComp.constructionPlanes
extrudes = rootComp.features.extrudeFeatures
firstSketch = sketches.add(xyPlane)
pos_1 = adsk.core.Point3D.create(three_points[0][0], three_points[0][1], three_points[0][2])
pos_2 = adsk.core.Point3D.create(three_points[1][0], three_points[1][1], three_points[1][2])
pos_3 = adsk.core.Point3D.create(three_points[2][0], three_points[2][1], three_points[2][2])
p_1 = firstSketch.sketchPoints.add(pos_1)
p_2 = firstSketch.sketchPoints.add(pos_2)
p_3 = firstSketch.sketchPoints.add(pos_3)
planeInput = planes.createInput()
planeInput.setByThreePoints(p_1, p_2, p_3)
threePointsPlane = planes.add(planeInput)
#threePointsPlane.name = 'Three-points plane'
sketch = sketches.add(threePointsPlane)
degree = 3
knots = [0, 0, 0, 0, 1, 1, 1, 1]
splines = sketch.sketchCurves.sketchFixedSplines
splines.isFixed = False
for index, p in enumerate(control_points):
weights = [1, 1, 1, 1]
weights[1], weights[2] = point_weights[index][0], point_weights[index][1]
point1 = adsk.core.Point3D.create (p[0][0],p[0][1],0)
point2 = adsk.core.Point3D.create (p[1][0],p[1][1],0)
point3 = adsk.core.Point3D.create (p[2][0],p[2][1],0)
point4 = adsk.core.Point3D.create (p[3][0],p[3][1],0)
points = [point1, point2, point3, point4]
nurbs = adsk.core.NurbsCurve3D.createRational(points, degree, knots, weights, False)
fixed_splines = splines.addByNurbsCurve(nurbs)
fixed_splines.isReference = False
distance = adsk.core.ValueInput.createByReal(height)
try:
body = extrudes.addSimple(sketch.profiles.item(0), distance, adsk.fusion.FeatureOperations.IntersectFeatureOperation)
except:
body = extrudes.addSimple(sketch.profiles.item(0), distance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
return body
def generate_model(rootComp, json_data, ui):
#print(json_data)
control_points = json_data["param"]["points"]
weights = json_data["param"]["weights"]
heights = json_data["param"]["heights"]
planes = json_data["param"]["planes"]
intersections = json_data["intersection"]
union = json_data["union"]
#ui.messageBox(str(weights[0][0]))
for c in range(len(intersections[0])):
if union[c]!=1:
continue
newCom = rootComp.occurrences.addNewComponent(adsk.core.Matrix3D.create())
revComp = newCom.component
for k in range(len(intersections)):
if intersections[k][c] == 1:
ext = generate_primitive(revComp, control_points[k], weights[k], heights[k], planes[k], 0)
break
def parse_json(rootComp, category,start_id, n, ui):
dir = "C:/Users/86454/Desktop/jsons/"+category
count = 0
#ui.messageBox(os.getcwd())
for index, file in enumerate(os.listdir(dir)):
if index < start_id:
continue
with open("{}/{}".format(dir, file), "r") as fp:
generate_model(rootComp, json.load(fp), ui)
count += 1
if count >= n:
break
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
rootComp = design.rootComponent
category = "bench"
id = 0
num = 1
parse_json(rootComp, category, id, num, ui)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
and here is what i want to achieve:
Solved! Go to Solution.