본문 바로가기
  • 환영 합니다 ! Welcome!
VBA For Creo

가로*세로*높이 사이즈 알아보기

by ToolBOX01 2021. 2. 16.
반응형

3D 형상을 BOX 형태의 사이즈를 알아보는 프로그램 입니다. CREO에서는 대각선 사이즈는 3D point를 제공 합니다. CREO의 사이즈 계산 기능 문제점은 데이텀 커브, 데이텀 평면, 서피스를 사이즈 계산에 포함 시킵니다.

[ CREO 사이즈 측정 ]


J-LINK)  사이즈 계산 코드

import com.ptc.cipjava.*;
import java.io.*;
import com.ptc.pfc.pfcGlobal.*;
import com.ptc.pfc.pfcSession.*;
import com.ptc.pfc.pfcBase.*;
import com.ptc.pfc.pfcSolid.*;
import com.ptc.pfc.pfcModelItem.*;
import com.ptc.pfc.pfcGeometry.*;
import java.awt.*;

public class diagonal{

  static Session session;
  static Solid solid; 
  static Outline3D outline;
  static Transform3D trans3;
  static Point3D point1,point2,point3;
  static double x, y, z,k,l,m,diagonal,p,q,r,sum;
  static CoordSystem cor;
  static ModelItems mitems;
  static ModelItemType item1  =ModelItemType.ITEM_AXIS;
  static ModelItemType item2  =ModelItemType.ITEM_POINT;
  static ModelItemType item3  =ModelItemType.ITEM_COORD_SYS;
  static ModelItemTypes modtyp;
  static String name;
    
  public static void start ()
  {
    try {
    session=pfcGlobal.GetProESession();
        solid =(Solid)session.GetCurrentModel();
        mitems=solid.ListItems(ModelItemType.ITEM_COORD_SYS);
        cor=(CoordSystem)mitems.get(0);
        trans3=cor.GetCoordSys();
        name=cor.GetName();
        System.out.println("The Name of the cordinate-system is "+name);
        point1=trans3.GetOrigin();              
        k=point1.get(0);
        l=point1.get(1);
        m=point1.get(2);
        System.out.println("The Value of x cordinate of origin is "+k);
        System.out.println("The Value of y cordinate of the origin is "+l);
        System.out.println("The Value of z coordinate of the origin is "+m);
        modtyp=ModelItemTypes.create();
        modtyp.set(0,item1);
        modtyp.set(1,item2);
        modtyp.set(2,item3);
        outline=solid.EvalOutline(trans3,modtyp);
        point2= outline.get(0);
        x = point2.get(0);
        y = point2.get(1);
        z = point2.get(2);
        point3=outline.get(1);
        p= point3.get(0);
        q = point3.get(1);
        r = point3.get(2);
        sum=Math.pow(p-x,2)+Math.pow(q-y,2)+Math.pow(r-z,2);
        diagonal=Math.sqrt(sum);
        new SuccessDialog(new Frame(), true, p-x, q-y, r-z,diagonal);
        System.out.println("The Value of the diagonal is "+diagonal);
        return;
    }
    catch (jxthrowable x1)
      {
        System.out.println("Exception caught: "+x1);
        x1.printStackTrace();
        System.exit(-1);
      }
 
  }
  
  public static void stop (){
    System.out.println("Stopping J-link ");
  }
}

PTC 사이트

 

CS189592 - How to use the J-Link Solid.EvalOutline() to duplicate Pro/ENGINEER #Info #Model Size functionality by determining th

A PTC Technical Support Account Manager (TSAM) is your company's personal advocate for leveraging the breadth and depth of PTC's Global Support System, ensuring that your critical issues receive the appropriate attention quickly and accurately.

www.ptc.com

 

IpfcSolid.EvalOutline 기능을 사용 하여, 솔리드 모델 사이즈를 계산 합니다.

- 좌표계를 기준으로 사이즈 계산을 합니다.  모델에서 좌표계의 이름은 "PRT_CSYS_DEF" 으로 정의 되어있어야 합니다
  아래 코드는 좌표계 위치에 따라 값이 달라 지고, "1.5" 정도 오류가 있습니다
- EpfcITEM_AXIS, EpfcITEM_COORD_SYS, EpfcITEM_POINT 사이즈 계산에서 제외 할 수 있습니다.
  (IpfcSolid.EvalOutline는 기능 제약이 있습니다)
- IpfcTransform3D 매소드는 좌표계를 행렬로 변환해 줍니다

 

Option Explicit
Sub TEMPLATE()

    Application.EnableEvents = False
    Dim asynconn As New pfcls.CCpfcAsyncConnection
    Dim conn As pfcls.IpfcAsyncConnection:
    
    '//////////////////////////////////////////////////////////////////////////////////////////////////////
    '// Creo Connect Check
    '//////////////////////////////////////////////////////////////////////////////////////////////////////
    On Error Resume Next
    Set conn = asynconn.Connect("", "", ".", 5)
    
        If conn Is Nothing Then
        
           MsgBox "Error occurred while starting new Creo Parametric Session!", vbInformation, "www.idt21c.com"
           Exit Sub
           
        End If
    '//////////////////////////////////////////////////////////////////////////////////////////////////////

    
    On Error GoTo RunError
    
    Dim oSession As pfcls.IpfcBaseSession: Set oSession = conn.Session
    Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
    Dim oSolid As IpfcSolid: Set oSolid = oModel
    Dim oWindows As IpfcWindow: Set oWindows = oSession.CurrentWindow
    
    
    '//////////////////////////////////////////////////////////////////////////////////////////////////////
    '// Active Models Check
    '//////////////////////////////////////////////////////////////////////////////////////////////////////
        If oModel Is Nothing Then
            
           MsgBox "No Active Models!", vbInformation, "www.idt21c.com"
           Exit Sub
        
        End If
    '//////////////////////////////////////////////////////////////////////////////////////////////////////
      
        
    Dim outline(3) As Double
    
    '// 사이즈 계산에 제외 항목들
    
    Dim oCreateModelItemTypes As CpfcModelItemTypes
    Dim excludeModelItemTypes As IpfcModelItemTypes
    
    Set excludeModelItemTypes = New CpfcModelItemTypes
    
    With excludeModelItemTypes
             
             .Append (EpfcModelItemType.EpfcITEM_AXIS)
             .Append (EpfcModelItemType.EpfcITEM_COORD_SYS)
             .Append (EpfcModelItemType.EpfcITEM_POINT)
             
    End With
            
    Dim oModelowner As IpfcModelItemOwner: Set oModelowner = oSolid
    Dim oCoordSystem As IpfcCoordSystem: Set oCoordSystem = oModelowner.GetItemByName(3, "PRT_CSYS_DEF")
    Dim oTransform3D As IpfcTransform3D: Set oTransform3D = oCoordSystem.CoordSys
    
     
    Dim outline3d As IpfcOutline3D
    Set outline3d = oSolid.EvalOutline(oTransform3D, excludeModelItemTypes)

    outline(0) = Math.Abs(outline3d.Item(1).Item(0) - outline3d.Item(0).Item(0))
    outline(1) = Math.Abs(outline3d.Item(1).Item(1) - outline3d.Item(0).Item(1))
    outline(2) = Math.Abs(outline3d.Item(1).Item(2) - outline3d.Item(0).Item(2))
      
    MsgBox outline(0)
    MsgBox outline(1)
    MsgBox outline(2)
    
 
    
    conn.Disconnect (2)
    
    'Cleanup
    Set asynconn = Nothing
    Set conn = Nothing
    Set oSession = Nothing
    Set oModel = Nothing
    
RunError:
    If Err.Number <> 0 Then
        MsgBox "Process Failed : Unknown error occurred." + Chr(13) + _
                "Error No: " + CStr(Err.Number) + Chr(13) + _
                "Error: " + Err.Description, vbCritical, "Error"
        If Not conn Is Nothing Then
            If conn.IsRunning Then
                conn.Disconnect (2)
            End If
        End If
    End If

End Sub

 

CREO OVERALL SIZE.xlsm
0.02MB

 

by lionkk@idt21c.com

 

 

 

CREO vbapi二次开发-10-外形尺寸 | 工匠之心

本节介绍使用VBAPI计算零件的外形尺寸。外形尺寸的计算与参照坐标系密切相关,VBAPI在IpfcSolid的GeomOutline属性可获得默认坐标系下外形尺寸,EvalOutline方法获得选定坐标系下的外形尺寸。EvalOutline

www.hudi.site

 

'VBA For Creo' 카테고리의 다른 글

CREO 파일 타입 알아보기  (0) 2021.02.18
Part List 프로그램  (0) 2021.02.16
재질 파일 설정  (0) 2021.02.15
무게와 관련된 매개변수  (0) 2021.02.15
#3 여러개의 drw 파일 → 2D pdf 파일 변환 프로그램  (0) 2021.02.12