⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas.~949~

📁 自动化控制visio
💻 ~949~
📖 第 1 页 / 共 3 页
字号:
             Add('--------Y:' + FloatToStr(y));


          {visioShape.get_RowCount(shortSectionProp) 获得属性的个数,遍历属性}
//          for I := 0 to visioShape.get_RowCount(visSectionProp) - 1 do
//          begin
//            shapeCell := visioShape.get_CellsSRC(visSectionProp, I, visCustPropsValue);
//            Add('------------属性' + IntToStr(I) + ':' + shapeCell.Formula);
//            shapeCell := visioShape.get_CellsSRC(visSectionProp, I, visCustPropsLabel);
//            Add('------------RowNameU:' + shapeCell.RowNameU);



            {
            shapeCell := visioShape.get_CellsSRC(visSectionProp, I, visCustPropsFormat);
            Add(shapeCell.FormulaU);
            }
            //shapeCell := visioShape.get_CellsSRC(visSectionProp, I, visCustPropsPrompt);
            //Add(shapeCell.FormulaU);
//          end;
//
//          Add('------------NameID:' + visioShape.NameID);
//          Add('------------NameU:' + visioShape.NameU);
//          Add('------------Text:' + visioShape.Text);

          {
            shape 有FromConnects
            FromSheet : 连接到本身的连接线
            ToSheet : 图形自己
          }
          if visioShape.FromConnects <> nil then
            shapeConns := visioShape.FromConnects;
            for J := 1 to shapeConns.Count do
            begin
              ConnShape := shapeConns[J].FromSheet;
              Add('------------连接线:' + ConnShape.Name);
              //ConnShape := shapeConns[J].ToSheet;
              //Add('------------ToSheet:' + ConnShape.Name);
              shapeToCell := shapeConns[J].ToCell;  //连接线连接的点
              Add('------------连接在图形的点:' + shapeToCell.Name);
              Add('------------ToCell:' + shapeToCell.Shape.Name);
              shapeToCell := shapeConns[J].FromCell;
              Add('------------FromCell:' + shapeToCell.Name);
              Add('------------FromCell:' + shapeToCell.Shape.Name);
              Add('--');

              LineShape := shapeConns[J].FromCell.Shape;
              if LineShape.Connects <> nil then
              begin
                for K := 1 to LineShape.Connects.Count do
                 begin
                // ConnedShape := LineShape.Connects[K].ToCell;
                 Add('------------连接到的图形tocell:' + LineShape.Connects[K].ToCell.Shape.Name);
                 Add('------------连接到的图形tosheet:' + LineShape.Connects[K].ToSheet.Name);
                 Add('------------连接到的图形fromsheet:' + LineShape.Connects[K].FromSheet.Name);

                  Add('--');
                 end;
              end;
            end;
          end;


              

              {
                连接线 有Connects
                FromSheet : 连接线自己
                ToSheet : 连接的两个图形
              }
//              if visioShape.Connects <> nil then
//                shapeConns := visioShape.Connects;
//                for J := 1 to shapeConns.Count do
//                begin
//                  ConnShape := shapeConns[J].ToSheet;
//                  Add('------------ToSheet:' + ConnShape.Name);
//                  ConnShape := shapeConns[J].FromSheet;
//                  Add('------------FromSheet:' + ConnShape.Name);
//                  shapeToCell := shapeConns[J].ToCell;
//                  Add('------------ToCell:' + shapeToCell.Name);
//                  Add('------------ToCell:' + shapeToCell.Shape.Name);
//                  shapeToCell := shapeConns[J].FromCell;
//                  Add('------------FromCell:' + shapeToCell.Name);
//                  Add('------------FromCell:' + shapeToCell.Shape.Name);
//                  Add('');
//                end;


          {
          Add('+++++' + visioShape.Data1);
          Add('+++++' + visioShape.Data2);
          Add('+++++' + visioShape.Data3);
           }
          //Add('--------' + visioShape.Master.Name);


        end;
      end;
    end;
  end;
        //Add(FloatToStr(visioShape.CellsU['Height'].Result['mm']));
end;

function XYDrawingToScreen(visWindow: Window; visX, visY: Double): TPoint;
var
  drawLeft, drawTop, drawHeight, drawWidth: Double;
  screenLeft, screenTop, screenHeight, screenWidth: Integer;
  screenX, screenY: Integer;
  pt: TPoint;
begin
  visWindow.GetViewRect(drawLeft, drawTop, drawWidth, drawHeight);
  visWindow.GetWindowRect(screenLeft, screenTop,screenWidth, screenHeight);
  screenX := Round(screenLeft + ((screenWidth / drawWidth) * (visX - drawLeft)));
  screenY := Round(screenTop + ((screenHeight / drawHeight) * (drawTop - visY)));
  pt := Point(screenX, screenY);
  //ClientToScreen(GetDC(0), pt);
  Result := Point(screenX, screenY);
end;

function XScreenToDrawing(visWindow: Window; screenX, screenY: Integer): Integer;
var
  drawLeft, drawTop, drawHeight, drawWidth: Double;
  screenLeft, screenTop, screenHeight, screenWidth: Integer;
  visX, visY: Integer;
begin
  visWindow.GetViewRect(drawLeft, drawTop, drawWidth, drawHeight);
  visWindow.GetWindowRect(screenLeft, screenTop,screenWidth, screenHeight);
//  visX := Round((screenX + (screenWidth / drawWidth) * drawLeft - screenLeft) / (screenWidth / drawWidth));
//  visX := Round((screenY + (screenHeight / drawHeight) * drawTop - screenTop) / (screenHeight / drawHeight));
  visX := Round(drawLeft + (drawWidth / screenWidth) * (screenX - screenLeft));
  visY := Round(drawTop + (drawHeight / screenHeight) * (screenTop - screenY));
  Result := visX;
end;

function YScreenToDrawing(visWindow: Window; screenX, screenY: Integer): Integer;
var
  drawLeft, drawTop, drawHeight, drawWidth: Double;
  screenLeft, screenTop, screenHeight, screenWidth: Integer;
  visX, visY: Integer;
begin
  visWindow.GetViewRect(drawLeft, drawTop, drawWidth, drawHeight);
  visWindow.GetWindowRect(screenLeft, screenTop,screenWidth, screenHeight);
  
//  visX := Round((screenX + (screenWidth / drawWidth) * drawLeft - screenLeft) / (screenWidth / drawWidth));
//  visY := Round((screenY + (screenHeight / drawHeight) * drawTop - screenTop) / (screenHeight / drawHeight));
  visX := Round(drawLeft + (drawWidth / screenWidth) * (screenX - screenLeft));
  visY := Round(drawTop + (drawHeight / screenHeight) * (screenTop - screenY));
  Result := visY;
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  VisioMaster: Master;
  VisioMasters: Masters;
  mastersDoc: Document;
  connectShape: Shape;
  pinCell, begCell, endCell: Cell;
  vsoCell: Cell;
  x, y, x1, y1: Integer;
  pt: TPoint;
  d: Double;
  str: string;
begin
  Memo1.Lines.Clear;
  try
    VisioApp := CoVisioApplication.Create;
    VisioApp.Settings.ShowChooseDrawingTypePane := False;
    VisioApp.Visible := True;
      Button2.Enabled := True;
      Button3.Enabled := True;
      Button4.Enabled := True;
      Button6.Enabled := True;
    
    visioDoc := VisioApp.Documents.Add('');  //新建绘图
    // BASFLO_M.vss ---基本流程图模板
    // 打开模具模板
    mastersDoc := visioDoc.Application.Documents.OpenEx('BASFLO_M.vss', visOpenDocked);
    //mastersDoc := VisioApp.Documents.OpenEx('BASFLO_M.vss', visOpenCopy); //另新建窗口显示了
    VisioMasters := mastersDoc.Masters;
    {
    Memo1.Lines.Add(VisioMasters.ItemFromID[0].NameU);
    I := 2;
    repeat
      with Memo1.Lines do
      begin
        Add(VisioMasters.ItemFromID[I].NameU);
        //Add(IntToStr(VisioMasters.get_ItemU('Document').ID));
      end;
      Inc(I);
    until I > VisioMasters.Count;
    }
    //VisioMaster := VisioMasters.ItemFromID[0];   //按ID号取得模具图形
    VisioMaster := VisioMasters.get_ItemU('Process');   //按NameU取得模具图形

    visioPage := visioDoc.Pages[1];
    visioshapes := visioPage.Shapes;


    x := XScreenToDrawing(VisioApp.ActiveWindow, 400, 400);
    y := YScreenToDrawing(VisioApp.ActiveWindow, 400, 400);
    visioPage.Drop(VisioMaster, x, y);
    visioPage.Drop(VisioMaster, 2, 3);
//    visioShape1 := visPgDrop(visioPage, VisioMaster, x, y);
//    visioShape1.Text := '开始';
//    visioShape1.Cells['Width'].Result['mm'] := 20;
//    visioshape1.Cells['Height'].Result['mm'] := 50;
//    visioapp.ActiveWindow.DeselectAll;
//    visioapp.ActiveWindow.Select(visioshape1, visselect);
//
//    x := XScreenToDrawing(VisioApp.ActiveWindow, 400, 400);
//    y := YScreenToDrawing(VisioApp.ActiveWindow, 400, 400);
//    visioShape := visPgDrop(visioPage, VisioMaster, x, y);
//    visioShape.Text := '结束';
//    visioShape.Cells['Width'].Result['mm'] := 20;
//    visioshape.Cells['Height'].Result['mm'] := 50;

//    visioapp.ActiveWindow.Select(visioshape, visselect);
//    visioapp.ActiveWindow.Selection.ConnectShapes;

//    pt := XYDrawingToScreen(VisioApp.ActiveWindow, 2, 2);
//    Memo1.Lines.Add('x:' + IntToStr(pt.x) + ';Y:' + IntToStr(pt.Y));
//    str := visioShape.TextStyle;
//    Memo1.Lines.Add(str);
//    str := IntToStr(visioShape.Get_type_);
//    memo1.Lines.Add(str);

//    x := XScreenToDrawing(VisioApp.ActiveWindow, 500, 300);
//    y := YScreenToDrawing(VisioApp.ActiveWindow, 500, 300);
//    visPgDrop(visioPage, VisioMaster, x, y);

//    //取得属性cell,设置属性值
//    vsoCell := visioShape.get_CellsSRC(visSectionProp, 2, visCustPropsValue);
//    vsoCell.Set_Formula('1231231');
//    //设置属性名称
//    vsoCell := visioShape.get_CellsSRC(visSectionProp, 1, visCustPropsLabel);
//    vsoCell.Set_RowNameU('chengben');
    //visioShape.AddSection(visSectionScratch);
    {
    vsoSection := visioShape.Section[1];
    visioShape.AddRow(visSectionLastComponent, 3, 0);
    vsoCell := visioShape.get_CellsSRC(visSectionProp, 3, visCustPropsLabel);
    vsoCell.Set_Formula('xinjia');
    }
    //vsoCell := visioShape.get_CellsSRC(visSectionProp, 1, visCustPropsFormat);
   // vsoCell.Set_FormulaU('成本成本');
    {
    visioShape := visioPage.DrawRectangle(1, 5, 5, 1);
    visioShape.AddSection(visSectionScratch);
    visioshape.AddRow(visSectionScratch, visRowScratch, 0);
    }
    {
    vsoCell := visioShape.Cells['Scratch.X1'];
    vsoCell.Formula := 'Min(Width, Height) / 5';
     }
//    VisioMaster := VisioMasters.get_ItemU('Dynamic connector');
//    connectShape := visPgDrop(visioPage, VisioMaster, 5, 5); //放连接线


//    str := IntToStr(connectShape.Get_type_);
//    memo1.Lines.Add(str);
//    str := connectShape.Style;
//    memo1.Lines.Add(str);
//    str := connectShape.LineStyle;
//    memo1.Lines.Add(str);
//    x1 := XScreenToDrawing(VisioApp.ActiveWindow, 20, 50);
//    y1 := YScreenToDrawing(VisioApp.ActiveWindow, 20, 50);

//    VisioMaster := VisioMasters.get_ItemU('Dynamic connector');
//    connectShape := visPgDrop(visioPage, VisioMaster, 1, 1); //放连接线
//    //connectShape.LineStyle :='Guide';
//    connectshape.SetBegin(3, 3);
//    connectShape.CellsSRC[visSectionObject,visRowShapeLayout,visSLOLineRouteExt].FormulaU := IntToStr(1);
//    connectshape.CellsSRC[visSectionObject,visRowShapeLayout,visSLORouteStyle].FormulaU := inttostr(16);
//    str := connectShape.CellsSRC[visSectionObject,visRowShapeLayout,visSLOLineRouteExt].FormulaU;
//    str := connectShape.CellsU['ConLineRouteExt'].ResultStr[''];
//    memo1.Lines.add(str);

//    visioShape := visioShapes.ItemU['Process'];
//    pinCell := visioShape.Cells['Connections.X2'];  //获得shape的连接点
//    begCell := connectShape.Cells['BeginX'];        //获得连接线的起始点
//    begCell.GlueTo(pinCell);                        //连接

    //x = shape.get_CellsSRC((short)visSectionObject, visRowXFormOut, (short)VisCellIndices.visXFormWidth).ResultIU;
  //  y = shape.get_CellsSRC((short)visSectionObject, (short)visRowXFormOut, (short)VisCellIndices.visXFormHeight).ResultIU;
//
//    VisioMaster := VisioMasters.get_ItemU('Process');
//    visioShape :=  visPgDrop(visioPage, VisioMaster, 5, 5);
//    visioShape.Text := '结束';
//    pinCell := visioShape.Cells['Connections.X1'];
//    endCell := connectShape.Cells['EndX'];
//    endCell.GlueTo(pinCell);
    //visioPage.DrawRectangle(1,2,2,1);
    //visPgDrop(visioPage, visioShape, 3, 3);

   // visioShape.CellsU[''].
//    Memo1.Lines.Add(visioShape.Name);
//    Memo1.Lines.Add(visioShape.NameU);
    visioDoc.SaveAsEx(ExtractFilePath(Application.ExeName) + 'test.vsd', 0);
  except
     VisioApp.Quit;
      Button2.Enabled := False;
      Button3.Enabled := False;
      Button4.Enabled := False;
      Button6.Enabled := False;
  end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -