Skip navigation
alexanderklapfer
Currently Being Moderated

Copy to new artboard with transformation in VBA

Aug 20, 2012 1:34 AM

Tags: #vba

Hallo Forum,

 

I have the common problem to resize the artboard to standardize technical illustrations to the format 50x50mm. So I found good help in the forum (thank you). I have some problem and may somebody can help me:

 

  • I would like to group the objects for further transformations
  • I would transform the group to 45mm and scale stroks and effects

N.B.: here It should be a test on landscape format

 

  • I would align the group to the page center

 

This is my code, may somebody can help me ?

 

Thank you to every replay

Regards Alex

 

Public Sub copy_paste_with_transformation ()

'Duplicates grouped items in a new document with landscape sensitive transformation

Set appRef = CreateObject("Illustrator.Application")

 

'calculate the size of objects do define if it's landscape or not

Bounds = appRef.ActiveDocument.VisibleBounds

 

'If the group is landscape the lenth should be 45mm otherwise the higth

 

appRef.ActiveDocument.GroupItems 'problem

appRef.ActiveDocument.SelectObjectsOnActiveArtboard 'may a solution for CS4 too

 

appRef.ActiveDocument.Resize(45, 45) 'problem

 

appRef.ActiveDocument.copy

 

Set newDocument = appRef.Documents.Add(aiDocumentCMYKColor, 50, 50) 'Paper size is 50mm

newDocument.Paste

 

'Align group to page center hrizontal and vertical

'???

 

End Sub

 
Replies
  • Currently Being Moderated
    Aug 20, 2012 11:15 AM   in reply to alexanderklapfer

    Im sorry I don't do VB ( a mac thing ) don't you just need translate x&y by some little math? Paste should put it at window centre… Have you tried changing the view?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 21, 2012 7:38 AM   in reply to alexanderklapfer

    Not in VB ( klingon ) but ExtendScript… May be you can look this up and translate?

     

    #target illustrator
     
    newDocGroup();
     
    function newDocGroup() {
     
              var mm = 2.83464567, grpFile, doc, scale;
     
              grpFile = File( Folder.desktop + '/Testing.ai' );
     
              doc = app.documents.add( DocumentColorSpace.CMYK, 50*mm, 50*mm );
     
              doc.groupItems.createFromFile( grpFile );
     
              if ( doc.pageItems[0].width >= doc.pageItems[0].height ) {
     
                        scale = ( 45*mm / doc.pageItems[0].width ) * 100;
     
              } else {
     
                        scale = ( 45*mm / doc.pageItems[0].height ) * 100;
     
              };
     
              doc.pageItems[0].resize( scale, scale, true, true, true, true, scale, Transformation.CENTER );
     
    };
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points