| 464 | |
| 465 | === Uporaba funkcije zaokrožitve, pozicioniranje valja na izbrano mesto, združevanje CAD modelov ter izvoz v STEP format === |
| 466 | |
| 467 | V naslednjem primeru so prikazane naslednje funkcije: |
| 468 | * zaokrožitve |
| 469 | * pozicioniranje elementa |
| 470 | * združevanje CAD modelov |
| 471 | * enostaven izvoz CAD modela v STEP format |
| 472 | |
| 473 | {{{ |
| 474 | #!python |
| 475 | ##Copyright 2011 Simon Kulovec (simon.kulovec@lecad.si) |
| 476 | ##This file is part of pythonOCC. |
| 477 | |
| 478 | ## Importanje razlicnih knjiznic |
| 479 | |
| 480 | # Uporabniski vmesnik GUI |
| 481 | from OCC.Display.SimpleGui import * |
| 482 | |
| 483 | # OpenCascade |
| 484 | from OCC.gp import * |
| 485 | from OCC.TopoDS import * |
| 486 | from OCC.GC import * |
| 487 | from OCC.BRepBuilderAPI import * |
| 488 | from OCC.BRepPrimAPI import * |
| 489 | from OCC.BRepFilletAPI import * |
| 490 | from OCC.BRepAlgoAPI import * |
| 491 | from OCC.Utils.Topology import * |
| 492 | from OCC.BRep import * |
| 493 | from OCC.Utils.DataExchange.STEP import STEPExporter |
| 494 | |
| 495 | # OCC.Display.SimpleGui.init_display() returns multiple |
| 496 | # values which are assigned here |
| 497 | display, start_display, add_menu, add_function_to_menu = \ |
| 498 | init_display() |
| 499 | |
| 500 | # Definiranje spremenljivk |
| 501 | myWidth = 50.0 |
| 502 | myThickness = 30.0 |
| 503 | myHeight = 70.0 |
| 504 | |
| 505 | # Definiranje zacetnih tock |
| 506 | aPnt1 = gp_Pnt(-myWidth / 2. , 0 , 0) |
| 507 | aPnt2 = gp_Pnt(-myWidth / 2. , -myThickness / 4. , 0) |
| 508 | aPnt3 = gp_Pnt(0 , -myThickness / 2. , 0) |
| 509 | aPnt4 = gp_Pnt(myWidth / 2. , -myThickness / 4. , 0) |
| 510 | aPnt5 = gp_Pnt(myWidth / 2. , 0 , 0) |
| 511 | |
| 512 | # Definiranje geometrije |
| 513 | aArcOfCircle = GC_MakeArcOfCircle(aPnt2,aPnt3 ,aPnt4) |
| 514 | aSegment1 = GC_MakeSegment(aPnt1 , aPnt2) |
| 515 | aSegment2 = GC_MakeSegment(aPnt4 , aPnt5) |
| 516 | |
| 517 | # Definiranje topologije |
| 518 | aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value()) |
| 519 | aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value()) |
| 520 | aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value()) |
| 521 | aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge() , aEdge2.Edge() ,\ |
| 522 | aEdge3.Edge()) |
| 523 | |
| 524 | # Izdelava celotnega profila - mirror |
| 525 | |
| 526 | xAxis = gp_OX() |
| 527 | aTrsf = gp_Trsf() |
| 528 | aTrsf.SetMirror(xAxis) |
| 529 | aBRepTrsf = BRepBuilderAPI_Transform(aWire.Shape() , aTrsf) |
| 530 | aMirroredShape = aBRepTrsf.Shape() |
| 531 | aMirroredWire = TopoDS_wire(aMirroredShape) |
| 532 | mkWire = BRepBuilderAPI_MakeWire() |
| 533 | mkWire.Add(aWire.Wire()) |
| 534 | mkWire.Add(aMirroredWire) |
| 535 | myWireProfile = mkWire.Wire() |
| 536 | |
| 537 | # Telo: Iz profila se izdela telo |
| 538 | myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile) |
| 539 | aPrismVec = gp_Vec(0 , 0 , myHeight) |
| 540 | myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face() , aPrismVec) |
| 541 | |
| 542 | # Telo: Dodamo zaokrozitve (fillet) |
| 543 | mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape()) |
| 544 | topology_traverser = Topo(myBody.Shape()) |
| 545 | for aEdge in topology_traverser.edges(): |
| 546 | mkFillet.Add(myThickness / 12. , aEdge) |
| 547 | myBody = mkFillet.Shape() |
| 548 | |
| 549 | # Dodajanje grla na steklenico (valj) |
| 550 | neckLocation = gp_Pnt(0, 0, myHeight) #Določitev lokacije valja |
| 551 | neckNormal = gp_DZ() #smer normale, v katero bomo valj izvlekli |
| 552 | neckAx2 = gp_Ax2(neckLocation, neckNormal) |
| 553 | |
| 554 | myNeckRadius = myThickness / 4 #radij valja |
| 555 | myNeckHeight = myHeight / 10 # višina valja |
| 556 | |
| 557 | mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2 , myNeckRadius , \ |
| 558 | myNeckHeight) |
| 559 | myNeck = mkCylinder.Shape(); |
| 560 | |
| 561 | myBody = BRepAlgoAPI_Fuse(myBody, myNeck) #dodajanje valja k obliki myBody |
| 562 | |
| 563 | # Izdelava sestava |
| 564 | aRes = TopoDS_Compound() #Določitev spremenljivke za sestav |
| 565 | aBuilder = BRep_Builder() |
| 566 | aBuilder.MakeCompound (aRes) |
| 567 | aBuilder.Add (aRes, myBody.Shape()) #Dodajanje različnih oblik v sestav aRes |
| 568 | |
| 569 | # Export to STEP () |
| 570 | my_step_exporter = STEPExporter("export_step_file.stp") #Določevanje imena STEP file.a |
| 571 | my_step_exporter.add_shape(aRes) #Dodajanje oblike v STEP file |
| 572 | my_step_exporter.write_file() |
| 573 | |
| 574 | # Izris oblike |
| 575 | display.EraseAll() |
| 576 | print dir(display) |
| 577 | display.DisplayShape(aRes) |
| 578 | |
| 579 | start_display() |
| 580 | }}} |