Changes between Version 6 and Version 7 of PythonOcc


Ignore:
Timestamp:
Dec 12, 2011, 2:55:40 PM (13 years ago)
Author:
skulovec
Comment:

Dodajanje primera: zaokrožitve, sestavi, STEP

Legend:

Unmodified
Added
Removed
Modified
  • PythonOcc

    v6 v7  
    424424}}}
    425425
     426== Povzetek -- KT vaj 12.12.2011 ==
     427
    426428=== Prikaz enostavnega izvoza STEP formata za eno obliko ===
    427429{{{
     
    450452from OCC.BRepPrimAPI import *
    451453
    452 # Pripravimo enostaven CAD primer za izvoz v STEP format
     454# Pripravimo enostavna CAD primera za izvoz v STEP format
    453455my_box_shape = BRepPrimAPI_MakeBox(50,50,50).Shape()
    454456my_sphere_shape = BRepPrimAPI_MakeSphere(20).Shape()
     
    460462my_step_exporter.write_file()
    461463}}}
     464
     465=== Uporaba funkcije zaokrožitve, pozicioniranje valja na izbrano mesto, združevanje CAD modelov ter izvoz v STEP format ===
     466
     467V 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
     481from OCC.Display.SimpleGui import *
     482
     483# OpenCascade
     484from OCC.gp import *
     485from OCC.TopoDS import *
     486from OCC.GC import *
     487from OCC.BRepBuilderAPI import *
     488from OCC.BRepPrimAPI import *
     489from OCC.BRepFilletAPI import *
     490from OCC.BRepAlgoAPI import *
     491from OCC.Utils.Topology import *
     492from OCC.BRep import *
     493from OCC.Utils.DataExchange.STEP import STEPExporter
     494
     495# OCC.Display.SimpleGui.init_display() returns multiple
     496# values which are assigned here
     497display, start_display, add_menu, add_function_to_menu = \
     498init_display()
     499
     500# Definiranje spremenljivk
     501myWidth = 50.0
     502myThickness = 30.0
     503myHeight = 70.0
     504
     505# Definiranje zacetnih tock
     506aPnt1 = gp_Pnt(-myWidth / 2. , 0 , 0)
     507aPnt2 = gp_Pnt(-myWidth / 2. , -myThickness / 4. , 0)
     508aPnt3 = gp_Pnt(0 , -myThickness / 2. , 0)
     509aPnt4 = gp_Pnt(myWidth / 2. , -myThickness / 4. , 0)
     510aPnt5 = gp_Pnt(myWidth / 2. , 0 , 0)
     511
     512# Definiranje geometrije
     513aArcOfCircle = GC_MakeArcOfCircle(aPnt2,aPnt3 ,aPnt4)
     514aSegment1 = GC_MakeSegment(aPnt1 , aPnt2)
     515aSegment2 = GC_MakeSegment(aPnt4 , aPnt5)
     516
     517# Definiranje topologije
     518aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
     519aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
     520aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())
     521aWire  = BRepBuilderAPI_MakeWire(aEdge1.Edge() , aEdge2.Edge() ,\
     522                                         aEdge3.Edge())
     523
     524# Izdelava celotnega profila - mirror
     525
     526xAxis = gp_OX()
     527aTrsf = gp_Trsf()
     528aTrsf.SetMirror(xAxis)
     529aBRepTrsf = BRepBuilderAPI_Transform(aWire.Shape() , aTrsf)
     530aMirroredShape = aBRepTrsf.Shape()
     531aMirroredWire = TopoDS_wire(aMirroredShape)
     532mkWire = BRepBuilderAPI_MakeWire()
     533mkWire.Add(aWire.Wire())
     534mkWire.Add(aMirroredWire)
     535myWireProfile = mkWire.Wire()
     536
     537# Telo: Iz profila se izdela telo
     538myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile)
     539aPrismVec = gp_Vec(0 , 0 , myHeight)
     540myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face() , aPrismVec)
     541
     542# Telo: Dodamo zaokrozitve (fillet)
     543mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape())
     544topology_traverser = Topo(myBody.Shape())
     545for aEdge in topology_traverser.edges():
     546    mkFillet.Add(myThickness / 12. , aEdge)
     547myBody = mkFillet.Shape()
     548
     549# Dodajanje grla na steklenico (valj)
     550neckLocation = gp_Pnt(0, 0, myHeight) #Določitev lokacije valja
     551neckNormal = gp_DZ() #smer normale, v katero bomo valj izvlekli
     552neckAx2 = gp_Ax2(neckLocation, neckNormal)
     553
     554myNeckRadius = myThickness / 4 #radij valja
     555myNeckHeight = myHeight / 10 # višina valja
     556
     557mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2 , myNeckRadius , \
     558                                          myNeckHeight)
     559myNeck = mkCylinder.Shape();
     560
     561myBody = BRepAlgoAPI_Fuse(myBody, myNeck) #dodajanje valja k obliki myBody
     562
     563# Izdelava sestava
     564aRes = TopoDS_Compound() #Določitev spremenljivke za sestav
     565aBuilder = BRep_Builder()
     566aBuilder.MakeCompound (aRes)
     567aBuilder.Add (aRes, myBody.Shape()) #Dodajanje različnih oblik v sestav aRes
     568
     569# Export to STEP ()
     570my_step_exporter = STEPExporter("export_step_file.stp") #Določevanje imena STEP file.a
     571my_step_exporter.add_shape(aRes) #Dodajanje oblike v STEP file
     572my_step_exporter.write_file()
     573
     574# Izris oblike
     575display.EraseAll()
     576print dir(display)
     577display.DisplayShape(aRes)
     578
     579start_display()
     580}}}