1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Code:Imports pfcls
Public Class pfcSolidExamples
Public Sub printMassProperties(ByRef session As IpfcBaseSession)
Dim model As IpfcModel
Dim solid As IpfcSolid
Dim solidProperties As IpfcMassProperty
Dim gravityCentre As New CpfcPoint3D
Try
'======================================================================
'Get the current solid
'======================================================================
model = session.CurrentModel
If model Is Nothing Then
Throw New Exception("Model not present")
End If
If (Not model.Type = EpfcModelType.EpfcMDL_PART) And
_(Not model.Type = EpfcModelType.EpfcMDL_ASSEMBLY) Then
Throw New Exception("Model is not a solid")
End If
solid = CType(model, IpfcSolid)
'======================================================================
'Get the solid properties. Optional argument in this method is the name
'of the coordinate system to use. If null, uses default
'======================================================================
solidProperties = solid.GetMassProperty(Nothing)
gravityCentre = solidProperties.GravityCenter
MsgBox("The solid mass is: " + solidProperties.Mass.ToString + Chr(13).ToString + _"The solid volume is: " +
solidProperties.Volume.ToString + Chr(13).ToString + _"The Centre of Gravity is at: " + Chr(13).ToString + _"X : " +
gravityCentre.Item(0).ToString + Chr(13).ToString + _"Y : " + gravityCentre.Item(1).ToString +
Chr(13).ToString + _"Z : " + gravityCentre.Item(2).ToString +
Chr(13).ToString)
Catch ex As Exception
MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)
Exit Sub
End Try
End Sub
End Class
1 2 3 4 5 6 7 8
$asynconn = Win32::OLE->new("pfcls.pfcAsyncConnection"); $conn = $asynconn->Connect( "", "", ".", 5 ); #$session = $conn->Session; #$mdlName = $session->CurrentModel->FileName; $solidProperties = $session->CurrentModel->GetMassProperty(Nothing); $Mass = $solidProperties->Mass; #print "mdlName: $mdlName", "\n"; print "Mass: $Mass", "\n";
1 2 3 4 5 6 7 8 9 10 11 12 13
use Win32::OLE; $asynconn = Win32::OLE->new("pfcls.pfcAsyncConnection"); $conn = $asynconn->Connect( "", "", ".", 5 ); $session = $conn->Session; $mdlName = $session->CurrentModel->FileName; $solidProperties = $session->CurrentModel->GetMassProperty(Nothing); $Mass = $solidProperties->Mass; print "solidProperties: $solidProperties", "\n"; print "mdlName: $mdlName", "\n"; print "Mass: $Mass", "\n"; $conn->Disconnect(2);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#use warnings; use Win32::OLE; $asynconn = Win32::OLE->new("pfcls.pfcAsyncConnection"); $conn = $asynconn->Connect( "", "", ".", 5 ); $session = $conn->Session; $mdlName = $session->CurrentModel->FileName; $model = $session->CurrentModel; #VBA code: solid = CType(model, IpfcSolid) $solid = IpfcSolid $model; # type casting ??? #VBA code: solidProperties = solid.GetMassProperty(Nothing) $solidProperties = $solid->$GetMassProperty(); $Mass = $solidProperties->Mass; print "model: $model", "\n"; print "solid: $solid", "\n"; print "solidProperties: $solidProperties", "\n"; print "mdlName: $mdlName", "\n"; print "Mass: $Mass", "\n";x $conn->Disconnect(2);
2011-10-29T20:28:13 ZuluIch habe den Kode analog zum VBA Beispiel erweitert:
Code (perl): (dl )1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22#use warnings; use Win32::OLE; $asynconn = Win32::OLE->new("pfcls.pfcAsyncConnection"); $conn = $asynconn->Connect( "", "", ".", 5 ); $session = $conn->Session; $mdlName = $session->CurrentModel->FileName; $model = $session->CurrentModel; #VBA code: solid = CType(model, IpfcSolid) $solid = IpfcSolid $model; # type casting ??? #VBA code: solidProperties = solid.GetMassProperty(Nothing) $solidProperties = $solid->$GetMassProperty(); $Mass = $solidProperties->Mass; print "model: $model", "\n"; print "solid: $solid", "\n"; print "solidProperties: $solidProperties", "\n"; print "mdlName: $mdlName", "\n"; print "Mass: $Mass", "\n";x $conn->Disconnect(2);
1
2
3
4
5
6
7
If model Is Nothing Then
Throw New Exception("Model not present")
End If
If (Not model.Type = EpfcModelType.EpfcMDL_PART) And
_(Not model.Type = EpfcModelType.EpfcMDL_ASSEMBLY) Then
Throw New Exception("Model is not a solid")
End If
1 2 3 4 5 6 7 8
[/c] if (!defined $model) { # vielleicht auch "if (! $model) {" die "Model not present"; } # Und dann versuchsweise: print 'model.Type ', $model->Type, "\n"; print 'EpfcModelType.EpfcMDL_PART ', EpfcModelType->EpfcMDL_PART, "\n"; print 'EpfcModelType.EpfcMDL_ASSEMBLY ', EpfcModelType->EpfcMDL_ASSEMBLY, "\n";
1 2 3 4
#VBA code: solid = CType(model, IpfcSolid) $solid = $model; # nur um weniger ändern zu müssen #VBA code: solidProperties = solid.GetMassProperty(Nothing) $solidProperties = $solid->GetMassProperty();
QuoteBeachte dass das $ vor GetMassProperty weg muss. Das ist einer der Fehler, die dir nach der Änderung von Zeile 1 nicht mehr durchrutschen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
use strict; use diagnostics; use warnings; use Win32::OLE; my $asynconn = Win32::OLE->new("pfcls.pfcAsyncConnection"); my $conn = $asynconn->Connect( "", "", ".", 5 ); my $session = $conn->Session; my $mdlName = $session->CurrentModel->FileName; my $model = $session->CurrentModel; ##VBA code: solid = CType(model, IpfcSolid) my $solid = $model; ##VBA code: solidProperties = solid.GetMassProperty(Nothing) my $solidProperties = $solid->GetMassProperty(''); use Data::Dumper; print Dumper($solidProperties); my $Mass = $solidProperties->Mass; print 'model.Type ', $model->Type, "\n"; print "solidProperties: $solidProperties", "\n"; print "mdlName: $mdlName", "\n"; print "Mass: $Mass", "\n";x $conn->Disconnect(2);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Win32::OLE(0.1709) error 0x8002000e: "Unzulõssige Parameteranzahl"
in METHOD/PROPERTYGET "Item" at E:/Perl/lib/Data/Dumper.pm line 190
Win32::OLE(0.1709) error 0x8002000e: "Unzulõssige Parameteranzahl"
in METHOD/PROPERTYGET "Item" at E:/Perl/lib/Data/Dumper.pm line 190
Win32::OLE(0.1709) error 0x8002000e: "Unzulõssige Parameteranzahl"
in METHOD/PROPERTYGET "Item" at E:/Perl/lib/Data/Dumper.pm line 190
Win32::OLE(0.1709) error 0x8002000e: "Unzulõssige Parameteranzahl"
in METHOD/PROPERTYGET "Item" at E:/Perl/lib/Data/Dumper.pm line 190
Win32::OLE(0.1709) error 0x8002000e: "Unzulõssige Parameteranzahl"
in METHOD/PROPERTYGET "Item" at E:/Perl/lib/Data/Dumper.pm line 190
Win32::OLE(0.1709) error 0x8002000e: "Unzulõssige Parameteranzahl"
in METHOD/PROPERTYGET "Item" at E:/Perl/lib/Data/Dumper.pm line 190
$VAR1 = bless( {
'Volume' => '4840878.56642907',
'SurfaceArea' => '243951.813242451',
'Density' => '1',
'Mass' => '4840878.56642907',
'GravityCenter' => bless( {
'Item' => undef
}, 'Win32::OLE' ),
'CoordSysInertia' => bless( {
'Item' => undef
}, 'Win32::OLE' ),
'CoordSysInertiaTensor' => bless( {
'Item' => undef
}, 'Win32::OLE' ),
'CenterGravityInertiaTensor' => bless( {
'Item' => undef
}, 'Win32::OLE' ),
'PrincipalMoments' => bless( {
'Item' => undef
}, 'Win32::OLE' ),
'PrincipalAxes' => bless( {
'Item' => undef
}, 'Win32::OLE' )
}, 'Win32::OLE' );
model.Type 1
solidProperties: Win32::OLE=HASH(0x2020a74)
mdlName: prt0001.prt
Mass: 4840878.56642907
1 2 3 4 5 6 7 8 9 10 11 12
my $new_value = 110; ##VBA code: item = CType(model, IpfcModelItemOwner).GetItemByName(EpfcModelItemType.EpfcITEM_DIMENSION, "durchmesser1") my $item = $model->GetItemByName(10,$ParamName); ##VBA code: CType(item, IpfcBaseParameter).Value = ((New CMpfcModelItem).CreateDoubleParamValue(new_value)) ##PERL GEHT NICHT: my $my_CMpfcModelItem = Win32::OLE->new("pfcls.CMpfcModelItem"); # FelherM.: "Ung³ltige Klassenzeichenfolge ##PERL GEHT NICHT: my $my_CMpfcModelItem = Win32::OLE->new("CMpfcModelItem"); # FelherM.: "Ung³ltige Klassenzeichenfolge ##PERL GEHT NICHT: $item->Value = $model->CMpfcModelItem->CreateDoubleParamValue($new_value); #FelherM.: "Mitglied nicht gefunden" ##PERL GEHT NICHT: $item->Value = $model->CreateDoubleParamValue($new_value); #FelherM.: "Mitglied nicht gefunden" ##PERL GEHT NICHT: $item->Value = $session->CMpfcModelItem->CreateDoubleParamValue($new_value); #FelherM.: "Mitglied nicht gefunden" ##PERL GEHT NICHT: $item->Value = $session->CreateDoubleParamValue($new_value); #FelherM.: "Mitglied nicht gefunden" $item->Value = ...???
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
use strict; #use diagnostics; use warnings; use Win32::OLE; use Win32::OLE::Const; my $asynconn = Win32::OLE->new("pfcls.pfcAsyncConnection"); my $EpfcModelItemType = Win32::OLE::Const->Load($asynconn); my $conn = $asynconn->Connect( "", "", ".", 5 ); my $session = $conn->Session; my $model = $session->CurrentModel; my $solid = $model; my $desired_parameter= $ARGV[0]; # zB 'd0' my $desired_value = $ARGV[1]; # zB 100.0 my $empty; my $old_mass = $solid->GetMassProperty('')->Mass; my $item = $model->GetParam($desired_parameter); my $old_value = $item->Value->Doublevalue; my $my_CMpfcModelItem = Win32::OLE->new("pfcls.MpfcModelItem"); my $my_value = $my_CMpfcModelItem->CreateDoubleParamValue($desired_value); $item->SetScaledValue($my_value,$empty); my $new_value = $item->Value->Doublevalue; $session->RunMacro("~ Command `ProCmdRegenPart`;"); my $new_mass = $solid->GetMassProperty('')->Mass; print 'old_value: ', $old_value, "\n"; print 'old_mass: ', $old_mass, "\n"; print 'new_value: ', $new_value, "\n"; print 'new_mass: ', $new_mass, "\n"; $conn->Disconnect(2);