2013-03-29 1 views
2

SketchUp (무료 버전, Mac)에서 간단한 플루트를 만드는 스크립트를 작성하고 있습니다. 튜브를 만들고 튜브를 뚫고 나서 튜브와 실린더 사이에 교차 선을 그려서 실린더를 지우고 튜브에서 자르는 원을 남기고 싶습니다.Sketchup Ruby API를 사용하여 실린더에 구멍을 뚫기

마우스로 조작하면 효과가 있지만 마우스로 배치하고 측정하는 것이 정확하지 않습니다. 지금까지는 스크립트로 작동하지 못했습니다. 현재 튜브에 불완전한 원을 그려 붙어있어 얼굴을 찾아 지울 수 없습니다. 루비 콘솔에서 다음 스크립트를 실행하고 무슨 뜻인지 볼 수 있어야합니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

entities = Sketchup.active_model.entities 

# make tube 
tube = entities.add_group 
tube_inner = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 5, 360 
tube_outer = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 6, 360 
cross_section_face = tube.entities.add_face tube_outer 
inner_face = tube.entities.add_face tube_inner 
tube.entities.erase_entities inner_face 
cross_section_face.pushpull -10, false 

# make a cylinder that punches through the wall 
hole_punch = entities.add_group 
hole_outer = hole_punch.entities.add_circle Geom::Point3d.new(0,0, 5), Geom::Vector3d.new(0,1,0), 3, 360 
face = hole_punch.entities.add_face hole_outer 
face.pushpull 10, false 

# draw the intersection lines and erase the hole punch 
entities.intersect_with true, hole_punch.transformation, tube, tube.transformation, true, hole_punch 
hole_punch.erase! 

답변

1

교차 후 지울 올바른 얼굴을 결정하는 것은 매우 까다 롭습니다.

그러나 솔리드 인 원통형 모양으로 작업하고 있으므로 SketchUp 8 Pro에 도입 된 솔리드 부울 연산을 사용하는 것이 좋습니다. 예를 들어 Group.subtract을 사용할 수 있습니다. http://www.sketchup.com/intl/en/developer/docs/ourdoc/group#subtract

그러나 SketchUp 8 Pro 이상을 사용하고 계시지 않으시면 사용 가능한 방법이 없습니다.


대체 솔루션 - 프로 버전의 솔리드 도구 방법 방지 : - 당신은 그룹 인스턴스를 확장하는 동안 정말 당신이 그룹까지의 내용을 확장 할 수있는 360 세그먼트 원을 원하는 경우에

entities = Sketchup.active_model.entities 

# (!) You created a circle with so many edges that at the scale 
#  you drew it they where pushing the boundary of how small 
#  units SketchUp can handle. (1/1000th inch). 
#  If you has Edge Outline style enabled you could see that 
#  not all edges where fully merged. 
#  I reduced the curve segments from 360 to 180. 
#  (Do you really need such a high mesh density anyway?) 

# make tube 
tube = entities.add_group 
tube_inner = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 5, 180 
tube_outer = tube.entities.add_circle Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1), 6, 180 
cross_section_face = tube.entities.add_face tube_outer 
inner_face = tube.entities.add_face tube_inner 
tube.entities.erase_entities inner_face 
cross_section_face.pushpull -10, false 

# make a cylinder that punches through the wall 
hole_punch = entities.add_group 
hole_outer = hole_punch.entities.add_circle Geom::Point3d.new(0,0, 5), Geom::Vector3d.new(0,1,0), 3, 180 
face = hole_punch.entities.add_face hole_outer 
face.pushpull 10, false 

# draw the intersection lines and erase the hole punch 
entities.intersect_with true, hole_punch.transformation, tube, tube.transformation, true, hole_punch 
hole_punch.erase! 

# Find all the edges that belong to the Circle elements drawn 
# earlier (including the ones push-pulled). 
# (Could also collect these earlier before intersecting by 
# collecting all non-smooth edges.) 
circles = tube.entities.grep(Sketchup::Edge).select { |e| e.curve }.uniq 
# Then we pick out all the faces that isn't connected to these edges and erase them. 
new_faces = tube.entities.grep(Sketchup::Face).select { |f| (f.edges & circles).empty? } 
entities.erase_entities(new_faces) 

을 하위. 그렇게하면 그룹 정의가 훨씬 더 커집니다. (SketchUp의 인스턴스 및 정의에 대한이 기사 참조)

또한 내면과 외장 스킨 사이의 구멍을 채우기 위해면을 채우려면 해당 부분도 교차해야합니다. Entities.intersect_with 설명에 대한


주 - 현재 문서는 물론 모든 인수를 설명하지 않습니다. 두 개의 entities 인수가 있습니다.

첫 번째 것은 교차 된 개체가 나타날 Sketchup::Entities 개체 여야합니다. (나는 조금 그것에게 Sketchup::Group 객체를 공급함으로써 일을 놀라게 해요.)

두 번째는 하지Sketchup::Entities해야한다 - 그 실패합니다. Sketchup:Entity 또는 배열이 Sketchup:Entity이어야합니다.

+0

나는 그 프로 버전에 대한 방법이 존재한다는 것을 알았지 만 문제는 Sketchup을 사용하여 Sketchup을 사용하여 500 달러를 지불하는 것을 정당화 할 수 없다는 것입니다. – wtbgtr

+0

오 잘. 그것은 실제로 저에게 문제를 해결하지는 않지만 다른 사람들에게는 문제를 해결할 수 있습니다. 그래서 대답을 받아 들일 것입니다. 제안 해 주셔서 감사합니다. – wtbgtr

+0

당신이 시도 할 수있는 대안을 추가했습니다. – thomthom

관련 문제