Sunteți pe pagina 1din 8

Login

Home

Jun 29
2011

About COE

Year Round Membership

Communities

Education & Collaboration

News

Sponsorship & Advertising

Forgot Your Passw ord?

COE Discussion Forum

Copy from drawing, Paste in sketch

open in browser PRO version

Login and view thread

Are you a developer? Try out the HTML to PDF API

Back to Topic Threads

Back to All Topics

pdfcrowd.com

Kurt
Schloemp
[Oakland
Community
College]

Copy from draw ing, Paste in sketch


June 29, 2011 07:06 PM

Hello,
I would like to start out with.. I am very new to VBA (or any VB)
I am looking for a solution to a problem i have.
I am trying to copy polylines from a drawing to a sketch.
the issue im having is after i have copied the polylines i cant seem to figure out how to paste them into my sketch.
here is my copy command.
Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument
Dim Copytext As Selection
Set Copytext = CATIA.ActiveDocument.Selection
Copytext.Clear
Copytext.Search ("Drafting.geometry,2DPolyline")
Copytext.Copy
so my Question is "how do i go about pasting this into a sketch in a CATpart?"

Thanks Kurt

Little
Cthulhu
[Sikorsky
Aircraft]

RE: Copy from draw ing, Paste in sketch


June 30, 2011 05:07 AM (in response to Kurt Schloemp)

Hi.
Basically, you paste anything from a buffer using Paste method. But in order for this action to make sense you need to specify not only
WHAT to paste, but also WHERE. So, where's target sketch located?

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Kurt
Schloemp

RE: Copy from draw ing, Paste in sketch


June 30, 2011 10:41 AM (in response to Kurt Schloemp)

[Oakland
Community

well, what I am trying to do is make a macro for making 3D text (branding)

College]

While in a CATPart working in solids


start macro
fill outs textbox
it opens a drawing and enters the text from the text box
it then saves as a ig2
closes drawing
opens ig2
copies all the polylines
then goes back to original CATPart
promps user to select a plane
creates a sketch
paste into the sketch
exits sketch
closes ig2
pads the sketch...

simple right.. lol, I have it working all the way up to the copy then makes the sketch.. but when it paste in to the sketch it doesnt work.

Jeff Roark

RE: Copy from draw ing, Paste in sketch

[Johnson

June 30, 2011 01:21 PM (in response to Kurt Schloemp)

Controls]

Little
Cthulhu
[Sikorsky
Aircraft]

might want to check the COE shareware library.

RE: Copy from draw ing, Paste in sketch


June 30, 2011 03:13 PM (in response to Kurt Schloemp)

Okay, I've remembered I've done this exact task before. And most likely it was even done on this forum.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Aircraft]

Create a new part document. Then create a sketch in it's main body (PartBody) and name it "MySketch". Finally, launch script below:
Sub CATMain()
' increase Selection perfomance
CATIA.HSOSynchronized = False
CATIA.RefreshDisplay = False
CATIA.DisplayFileAlerts = False
' get active Part document
Dim PrtDoc As PartDocument
Set PrtDoc = CATIA.ActiveDocument
' create new drawing document
Dim DrwDoc As DrawingDocument
Set DrwDoc = CATIA.Documents.Add("Drawing")
' create a text "My Text" in it
Dim DrwText As DrawingText
Set DrwText = DrwDoc.Sheets.Item(1).Views.Item(1).Texts.Add("My Text", 0, 0)
' save document as .ig2 file
DrwDoc.ExportData "C:\tmp\drawing1.ig2", "ig2"
DrwDoc.Close
' open .ig2 document
Dim Ig2Doc As Document
Set Ig2Doc = CATIA.Documents.Open("C:\tmp\drawing1.ig2")
' get selection object of .ig2 document
Dim Ig2Selection As Selection
' Set Ig2Selection = Ig2Doc.Selection Doesn't work
Set Ig2Selection = CATIA.ActiveDocument.Selection

' search for all polylines


Ig2Selection.Search "Drafting.Polyline,all"

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

' copy polylines found to a buffer


Ig2Selection.Copy
' get selection object of Part document
PrtDoc.Activate
Dim PrtSelection As Selection
Set PrtSelection = CATIA.ActiveDocument.Selection
' get sketch named "MySketch" located in PartBody
Dim RootPart As Part
Set RootPart = PrtDoc.Part
Dim TargetSketch As Sketch
Set TargetSketch = RootPart.MainBody.Sketches.Item("MySketch")
' open sketch for edition
TargetSketch.OpenEdition
' paste contents of a buffer (polylines from .ig2 document) in the sketch
PrtSelection.Clear
PrtSelection.Add TargetSketch
PrtSelection.Paste
' end sketch edition
TargetSketch.CloseEdition
' update part
RootPart.Update
' close Ig2 document
Ig2Doc.Close
' restore default Selection perfomance
CATIA.RefreshDisplay = True
CATIA.DisplayFileAlerts = True
CATIA.HSOSynchronized = True

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

End Sub

Please note, that not all letters are transformed in polylines when exported to .ig2. In my sample text ("My Text") converted "x" letter is
formed by two lines, not single polyline.

Kurt
Schloemp
[Oakland
Community
College]

RE: Copy from draw ing, Paste in sketch


July 5, 2011 11:44 AM (in response to Kurt Schloemp)

CatiaFidelity, that worked well


I have another question.. I would like this macro to create the sketch as well so the user only has to create the plane.
at this time i can get the sketch to be created and paste into that sketch but it is from a plane I have named.. I would like it to ask the user to
select a plane
would SelectElement2 be my best choice?
how do you use SelectElement2 to grab a selected plane?

Little
Cthulhu
[Sikorsky
Aircraft]

RE: Copy from draw ing, Paste in sketch


July 5, 2011 12:19 PM (in response to Kurt Schloemp)

Something like this should do the job:


'--------------------' SELECT A PLANE
'--------------------' get Selection object on Object interface
Dim varSelection ' as Object
Set varSelection = CATIA.ActiveDocument.Selection
' define types of objects that user is allowed to select
Dim ArrSelFilter(0)
ArrSelFilter(0) = "Plane"

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

' launch interactive selection command


Dim sResult ' as String
sResult = varSelection.SelectElement2(ArrSelFilter, "Select a plane to be used as a base for the sketch...", False)
If (varSelection.Count = 0) Then
' nothing has been selected, exit current Sub
Exit Sub
End If
' retrieve selected plane
Dim plnSketchPlane ' as Plane
Set plnSketchPlane = varSelection.Item(1).Value
'--------------------' CREATE A SKETCH
'--------------------' get Part root (suppose we have part document loaded)
Dim prtRoot as Part
Set prtRoot = CATIA.ActiveDocument.Part
' create Reference for the plane
Dim refSketchPlane ' as Reference
Set refSketchPlane = prtRoot.CreateReferenceFromObject(plnSketchPlane)
' create a sketch on the plane and put it in the PartBody
Dim TargetSketch as Sketch
Set TargetSketch = prtRoot.MainBody.Sketches.Add(refSketchPlane)

Kurt
Schloemp
[Oakland
Community

RE: Copy from draw ing, Paste in sketch


July 5, 2011 01:06 PM (in response to Kurt Schloemp)

thanks, that works.. and i learned something. (which is what really counts.)

College]

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

All Times America/New_York


Copyright 2013 COE. All Rights Reserved
800-COE-CALL - 330 N. Wabash Ave, Suite 2000 - Chicago, IL 60611 USA
All material, files, logos and trademarks within this site are properties of their respective organizations.
Terms of Service - Privacy Policy - Contact

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

S-ar putea să vă placă și