재질 파일이 설정된 Part 파일에서 밀도. 부피 값을 가져오는 코드 입니다. 무게는 밀도 값 * 부피로 표시 합니다.
Part 파일의 단위는 mm. gram 입니다.
1. Part 파일의 재질 파일 이름 가져오기
Sub MaterialName()
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
Dim oSession As IpfcBaseSession: Set oSession = conn.Session
Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
Dim oPart As IpfcPart
Dim oMaterial As IpfcMaterial
If oModel.Type = EpfcModelType.EpfcMDL_PART Then
Set oPart = oModel
Set oMaterial = oPart.CurrentMaterial
MsgBox oMaterial.Name
End If
'Disconnect with Creo
conn.Disconnect (2)
End Sub
2. 재질 파일 지정 하기
Sub MaterialSet()
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
Dim oSession As IpfcBaseSession: Set oSession = conn.Session
Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
Dim oPart As IpfcPart
Dim oMaterial As IpfcMaterial
' Set material
Set oPart= oModel
Set oMaterial = oPart.RetrieveMaterial("steel.mtl")
oPart.CurrentMaterial = oMaterial
3. 재질 파일에서 밀도값 가져오기
Sub MaterialDensity()
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
Dim oSession As IpfcBaseSession: Set oSession = conn.Session
Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
Dim oPart As IpfcPart
Dim oMaterial As IpfcMaterial
If oModel.Type = EpfcModelType.EpfcMDL_PART Then
Set oPart = oModel
Set oMaterial = oPart.CurrentMaterial
MsgBox oMaterial.MassDensity
End If
'Disconnect with Creo
conn.Disconnect (2)
End Sub
4. 부피 가져오기
Sub MaterialName()
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
Dim oSession As IpfcBaseSession: Set oSession = conn.Session
Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
Dim oPart As IpfcPart
Dim oSolid As IpfcSolid: Set oSolid = oModel
Dim oMassProperty As IpfcMassProperty
Dim oVolume As Double
If oModel.Type = EpfcModelType.EpfcMDL_PART Then
Set oMassProperty = oSolid.GetMassProperty("")
oVolume = oMassProperty.Volume
MsgBox oVolume
End If
'Disconnect with Creo
conn.Disconnect (2)
End Sub
5. 무게 가져오기
Sub MaterialMass()
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
Dim oSession As IpfcBaseSession: Set oSession = conn.Session
Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
Dim oPart As IpfcPart
Dim oSolid As IpfcSolid: Set oSolid = oModel
Dim oMassProperty As IpfcMassProperty
Dim oVolume As Double
If oModel.Type = EpfcModelType.EpfcMDL_PART Then
Set oMassProperty = oSolid.GetMassProperty("")
oVolume = oMassProperty.Mass
MsgBox oVolume
End If
'Disconnect with Creo
conn.Disconnect (2)
End Sub
참고 사이트] 무게와 관련된 매개변수
무게와 관련된 매개변수
자동 무게 계산 프로그램 IpfcSolid.GetMassProperty() 부품 또는 어셈블리의 질량 분포에 대한 정보를 제공합니다. 다음과 같은 Mass Property Object를 리턴 합니다. 계산을 위한 좌표계가 필요 합니다. 좌표
tool-2020.tistory.com
주의] 부동소수점 e 읽는 방법
Float, double등의 부동소수점 표시에서 "100e-6"와 같은 숫자가 나옵니다.'e'는 소수점이라 생각하면 되고,-6은
소수점을 왼쪽으로 6칸 이동(나눗셈)한다고 생각하면 됩니다.(+6은 소수점을 오른쪽으로 6칸 이동(곱셈) )그래서,
100e-6은 100을 1000000으로 나눈값과 동일합니다. 100e-6=100/1000000.0f2.4453e9=2.4453f*1000000000f
숫자뒤의 f는 실수를 나타냅니다.(정수가 아닌 실수)
부동소수점 e에 대해서...
매우 큰 수(양수 또는 음수)를 부동소수점으로 표현할 때는 E혹은 e를 이용하여 숫자에 지수를 추가할 수 있다. 지수가 있는 숫자 값은 E 앞에 있는 숫자에 10을 지수번 만큼 곱한 값이다. 12e2 라면
ryuseunghyun.tistory.com
'VBA, VB.NET For Creo' 카테고리의 다른 글
MAPKEY 실행하기 (1) | 2022.10.07 |
---|---|
IpfcBaseSession.SetConfigOption() (0) | 2022.10.07 |
Creo File 정보 얻기 Ver 0.2 (0) | 2022.10.04 |
모델의 Feature 정보를 알아보는 프로그램 Ver 0.1 (0) | 2022.10.02 |
#7 IpfcBaseSession.Select() : Feature 선택 하기 (0) | 2022.10.02 |