Sketch a Custom Propertie on a planar face of an occurence in an assembly.

Sketch a Custom Propertie on a planar face of an occurence in an assembly.

hkempeneers
Advocate Advocate
692 Views
8 Replies
Message 1 of 9

Sketch a Custom Propertie on a planar face of an occurence in an assembly.

hkempeneers
Advocate
Advocate

Hi,

We try to place a sketch with a Custom Propertie on a planar face of all appearances in an assembly. Each appearance has an unique Description and in this case we want to see them in the assembly.

I have write the following iLogic code: (The error message is below)

Does anyone know what I'm doing wrong?

Rule 27.JPGRule 27_Error.JPG

0 Likes
Accepted solutions (1)
693 Views
8 Replies
Replies (8)
Message 2 of 9

MjDeck
Autodesk
Autodesk

You didn't include any declaration or assignment to the variable named oOccurrence. Can you post your complete rule as a text file?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 3 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support

@hkempeneers,

 

Below modification may be helpful in creating sketch after selection of face.

 

    Dim oFace As Face
    oFace = ThisApplication.CommandManager.Pick(kPartFacePlanarFilter, "Select a face")
    
    Dim occ As ComponentOccurrence
    occ = oFace.ContainingOccurrence
    
    Dim oFaceProxy As FaceProxy
    
    Call occ.CreateGeometryProxy(oFace, oFaceProxy)
    
    If oFaceProxy.SurfaceType = kPlaneSurface Then
        oSketch = oAssDef.Sketches.Add(oFaceProxy)
    End If

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 9

hkempeneers
Advocate
Advocate

@MjDeck 

Dim comp As Object
Dim oAssDoc As Object

comp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Selecteer een component")

oAssDoc = comp

If TypeOf oOccurrence Is ComponentOccurrenceProxy Then
Prop = iProperties.Value(oAssDoc.NativeObject.Name, "Project", "Description")
Else
Prop = iProperties.Value(oAssDoc.Name, "Project", "Description")
End If

Dim oAssDef As AssemblyComponentDefinition = oAssDoc.Definition


Dim oFace As Face
oFace = ThisApplication.CommandManager.Pick (SelectionFilterEnum.kAllPlanarEntities,"Selecteer een vlak")

' make sure it Is a planar face
If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then

oPlanarSurface = oFace.Geometry

'add a sketch
oSketch = oAssDef.Sketches.Add(oFace)

'trying to choose an appropriate point
'assume this planar face has one edge loop only
oEdgeLoop = oFace.EdgeLoops(1)

oMinPt = oEdgeLoop.RangeBox.MinPoint
oMaxPt = oEdgeLoop.RangeBox.MaxPoint

CenterPt = oAssDef.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)

'get one point on the face and transform to the point2d on the sketch
'oTextPt = oSketch.ModelToSketchSpace(oPlanarSurface.RootPoint)
oTextPt = oSketch.ModelToSketchSpace(CenterPt)

'add the textbox
oSketchText = oSketch.TextBoxes.AddFitted(oTextPt, "<StyleOverride FontSize='30'>" & Prop & "</StyleOverride>")

Else
MsgBox( "Selecteer een vlak, en geen ronding, aub!")
End If

0 Likes
Message 5 of 9

hkempeneers
Advocate
Advocate

@chandra.shekar.g 

 

This modification doesn't fix my problem.

The same error message continues to appear.

 

0 Likes
Message 6 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support

@hkempeneers,

 

Can you please answer below questions?

 

  1. iProperty value of "Description" is taken from Top assembly or Selected occurrence?
  2. Sketch is  created in Top assembly or selected occurrence?
  3. Selected occurrence is assembly document or part document?

It's very confusion in coding.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 9

hkempeneers
Advocate
Advocate

@chandra.shekar.g 

 

Sorry for confusing you.

I still have to gain experience in programming..

 

1. From selected occurrence

2. Created in Top assembly

3. Selected occurrence can be both part of assy.

0 Likes
Message 8 of 9

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@hkempeneers,

 

Try below iLogic code.

Dim comp As ComponentOccurrence   
comp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Selecteer een component")  

If TypeOf oOccurrence Is ComponentOccurrenceProxy Then

    Prop = iProperties.Value(comp.NativeObject.Name, "Project", "Description")

Else 

    Prop = iProperties.Value(comp.Name, "Project", "Description")

End If 

Dim oAssDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition

Dim oFace As Face

oFace = ThisApplication.CommandManager.Pick (SelectionFilterEnum.kAllPlanarEntities,"Selecteer een vlak") 

'		make sure it Is a planar face

If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then

		Dim oFaceProxy As FaceProxy 
		comp.CreateGeometryProxy(oFace, oFaceProxy)

		oPlanarSurface = oFace.Geometry 
		'add a sketch

		oSketch = oAssDef.Sketches.Add(oFaceProxy)  

		'trying to choose an appropriate point

		'assume this planar face has one edge loop only

		oEdgeLoop = oFaceProxy.EdgeLoops(1) 

		oMinPt = oEdgeLoop.RangeBox.MinPoint 

		oMaxPt = oEdgeLoop.RangeBox.MaxPoint 

		CenterPt = ThisApplication.TransientGeometry.CreatePoint((oMaxPt.X + oMinPt.X) / 2#, (oMaxPt.Y + oMinPt.Y) / 2#, (oMaxPt.Z + oMinPt.Z) / 2#)    

		'get one point on the face and transform to the point2d on the sketch 

		'oTextPt = oSketch.ModelToSketchSpace(oPlanarSurface.RootPoint)

		oTextPt = oSketch.ModelToSketchSpace(CenterPt) 

		'add the textbox

		oSketchText = oSketch.TextBoxes.AddFitted(oTextPt, "<StyleOverride FontSize='30'>" & Prop & "</StyleOverride>")

Else

		MsgBox( "Selecteer een vlak, en geen ronding, aub!")

End If

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 9 of 9

hkempeneers
Advocate
Advocate

@chandra.shekar.g 

 

This code works great!

Many thanks!

0 Likes