miércoles, 21 de diciembre de 2022

Google Slides EXPRESS

Per tal de crear una presentació Google d'unes fotos amb un text concret a cada foto, amb un mínim de temps rècord, procedirem:

  1. Creem una presentació de Google Slides
  2. Creem una carpeta exclusiva d'imatges als Google Drive
  3. Obrim un Script dins de Google Slides (Extensions > App Scripts)
A l'editor de l'Scripts hi enganxarem el programa adjunt més avall. Encara que abans caldrà modificar-lo en els punts marcats en taronja, groc i verd.

El valor ID de la presentació i de l'ID de la carpeta el llegim i copiem del browser. 

Per a la presentació el trobem: 

    • just després de https://docs.google.com/presentation/d/...
    • i just abans de .../edit
Per a la carpeta és a partir de 
    • https://drive.google.com/drive/u/0/folders/...
Finalment, els títols que van a cada diapositiva, els anotem dins mateix del programa: 
  • sempre entre cometes "títol"
  • i acabat amb un coma "títol que sigui",
  • l'últim títol no porta coma "titol últim"
Nota important: els valors escrits entre parèntesi (1366 i 768) setWidth(1366).setHeight(768
corresponen als píxels de la imatge. Els podem conèixer fent botó dret sobre la imatge de qualsevol dels fitxers de la carpeta. Per anar bé, tots haurien de tenir el mateix tamany, si no, haurem de modificar-los un cop obtinguem el google Slides confeccionat.

El programa a introduir a l'Script és:


function insertListIntoSlides(presentationIdfolderIdlist) {
  var presentation = SlidesApp.openById(presentationId);
  var slide = presentation.getSlides()[0];
  var pictures = DriveApp.getFolderById(folderId).getFilesByType(MimeType.PNG);
 
  for (var i = 0i < list.lengthi++) {
    slide = presentation.insertSlide(i + 1);
    if (pictures.hasNext()) {
      var picture = pictures.next();
      var image=slide.insertImage(picture.getBlob());
      image.setWidth(1366).setHeight(768).setTop(0).setLeft(0).scaleHeight(0.5).scaleWidth(0.5);
    }
    const shape = slide.insertTextBox(list[list.length-1-i],3030500100);
    shape.getText().getTextStyle().setFontSize(40).setForegroundColor(255,0,0);
 
  }
}
 
var presentationId = "id_delaPresentacióGoogleSlides";
var folderId = "id_delaCarpetaAmbImatgesPNG";
var list = [
"aligned",
"one pair of poles",
"two pair of poles",
"shunt and series"
 ];
 
insertListIntoSlides(presentationIdfolderIdlist);
 
 


martes, 20 de diciembre de 2022

Google Slides con texto - script

 function insertListIntoSlides(presentationIdlist) {

  var presentation = SlidesApp.openById(presentationId);
  var slide = presentation.getSlides()[0];
  for (var i = 0i < list.lengthi++) {
    slide = presentation.insertSlide(i + 1);
    const shape = slide.insertTextBox(list[i],3030500100);
    shape.getText().getTextStyle().setFontSize(40);
  }
}

var presentationId = "colocar el ID entre comillas (se puede obtener en el mismo url)";
var list = ["sentence 1""sentence 2""sentence 3"];
insertListIntoSlides(presentationIdlist);

martes, 13 de diciembre de 2022

Animación sencilla en Autocad de un motor corriente continua

Determinamos UCS para el centro de giro, con eje Z

con el editor de texto creamos un script .scr

_rotate
g
1

0,0
-4
_rscript


Obtenemos la rotación llamando al script creado y luego Intro sucesivas veces (Autocad se bloquea...)

Con ezgif creamos una animación gif





Modelo y Papel en Autocad

 en línea comandos TILEMODE

  • 1 como siempre
  • 0 con fondo blanco... 



jueves, 24 de noviembre de 2022

my_first_autocad_plugin (https://knowledge.autodesk.com/support/autocad/learn-explore/caas/simplecontent/content/lesson-2-getting-to-know-your-development-environment.html)

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
Namespace HorizontalAttributes
 
    Public Class Commands
        Private Shared myOverrule As KeepStraightOverrule
        <CommandMethod("KeepStraight")>
        Public Shared Sub ImplementOverrule()
            If myOverrule Is Nothing Then
                myOverrule = New KeepStraightOverrule
                Overrule.AddOverrule(RXClass.GetClass(GetType(AttributeReference)), myOverrule, False)
            End If
            Overrule.Overruling = True
        End Sub
    End Class
 
    Public Class KeepStraightOverrule
        Inherits TransformOverrule
        Public Overrides Sub TransformBy(ByVal entity As Entity, ByVal transform As Matrix3d)
            MyBase.TransformBy(entity, transform)
            Dim attRef As AttributeReference = entity
            attRef.Rotation = 0.0
        End Sub
    End Class
End Namespace

lunes, 7 de noviembre de 2022

EXCEL com detectar el color de fons d'una cel·la

 https://www.exceldemy.com/excel-get-cell-color/

The GET.CELL Function: an Overview

We are using GET.CELL to return more information about the worksheet setting than is achievable with the CELL function. We don’t need any VBA code here to implement this.

The Basic Syntax:

=GET.CELL(type_num, reference)

type_num is a number that specifies what type of cell information you want.

The following list shows the possible values of type_num and the corresponding results.

One problem is that you cannot use the GET.CELL directly in the worksheet.

The steps are as stated below:

1. Go to Formulas >Name Manager. A Name Manager dialog box will appear.

2. Then, click on New.

excel name manager dialog box

3. Give it any name.

4. In the Refers to box, type the following format:

=GET.CELL(63,INDIRECT("rc",FALSE))

As we are working with background colors, we are using 63 in the type_num argument.

excel get.cell function to get cell color

5. Finally, click Ok.

Now, you can use the GET.CELL with the name that you have given.

jueves, 27 de octubre de 2022

Detecció de duplicats en llistes - FuzzyWuzzy (Python)

from fuzzywuzzy import fuzz

with open('C:/Users/JF/Desktop/llistaNoms.txt','r',encoding='utf-8') as f:
    my_list = list(f)

for i in range(len(my_list)-1):
    for j in range(i+1,len(my_list)):
        Str1=(my_list[i])
        Str2=(my_list[j])
        Ratio = fuzz.ratio(Str1.lower(),Str2.lower())
        Partial_Ratio = fuzz.partial_ratio(Str1.lower(),Str2.lower())
        Token_Sort_Ratio = fuzz.token_sort_ratio(Str1,Str2)
        Token_Set_Ratio = fuzz.token_set_ratio(Str1,Str2)
        
        if (Ratio>80)|(Partial_Ratio>80)|(Token_Sort_Ratio>80)|(Token_Set_Ratio>80):
            print(i+1,j+1, Ratio, Partial_Ratio,Token_Sort_Ratio,Token_Set_Ratio)

viernes, 21 de octubre de 2022

Combinació de valors de dues columnes ABCD... i abcd... resultant Aa Ab Ac Ad... Ba Bb Bc Bd... (Excel VBA) Alt+F11

 Sub Macro1()

Dim CantFilaCol1 As Long
Dim CantFilaCol2 As Long
Dim m As Single

CantFilaCol1 = Cells(Rows.Count, 1).End(xlUp).Row
CantFilaCol2 = Cells(Rows.Count, 2).End(xlUp).Row

m = CantFilaCol1 + 2

For fCol1 = 1 To CantFilaCol1 Step 1
    For fCol2 = 1 To CantFilaCol2 Step 1
        Cells(m, 1).Value = Cells(fCol1, 1).Value & " " & Cells(fCol2, 2).Value
        m = m + 1
    Next fCol2
Next fCol1

End Sub

jueves, 6 de octubre de 2022

Afegir text en un vídeo - OBS + OpenShot Video + Processing

Amb l'OBS hem gravat un vídeo-tutorial. 

Volem anotar textos al vídeo. Són frases curtes que volem sobreescriure al vídeo.

Utilitzem el programa OpenShot Video. Allà podem descarregar els textos en format SVG

Per tal d'agilitzar la creació dels textos, automatitzem el procés amb Processing. El programa desa els frames.

El fitxer list.txt conté el text que volem que aparegui. És una matriu amb frases. El processing crearà tantes imatges SVG com linies que contingui el fitxer list.txt .

import processing.svg.*;
int i,iLast,llargada;

void setup() {
size(400, 400);
}

void draw() {
    beginRecord(SVG, "C:/.../frame-####.svg");
    String[] lines = loadStrings("C:/.../list.txt");
    int llargada=lines.length;
    textSize(60); fill(0, 408, 612);
    text(lines[iLast], 40, 150, 280, 320);
    if (iLast+1==llargada){
      endRecord();
      exit();
    }
    iLast++;
}


jueves, 25 de agosto de 2022

Calcula l'àrea 2

 Pren el radi =2 cm


Ara resol:

https://www.mongge.com/ejercicios/761





Matriu f x c -> una sola columna a partir de files amb cel·les no buides

 Sub Macro1()

Dim CantFila As Long
Dim CantCol As Long
Dim c As Single, f As Single, m As Single, n As Single
Dim a As Variant

m = 26 'a partir de la fila 26
n = 1

CantFila = Cells(Rows.Count, 2).End(xlUp).Row
CantCol = Cells(2, Columns.Count).End(xlToLeft).Column

For f = 1 To CantFila Step 1
    For c = 1 To CantCol Step 1

    If (Cells(f, c).Value <> "") Then
        a = Cells(f, c).Value
        Cells(m, 1).Value = a
        m = m + 1
    
    Else
        f = f + 1
        c = 1
        a = Cells(f, c).Value
        Cells(m, 1).Value = a
        m = m + 1
      
    End If

    Next c
Next f

End Sub


Array resize - arranjament matriu comparant tres primers caràcters





 Sub Macro1()

Dim CantFila As Long
Dim CantCol As Long
Dim c As Single, f As Single, m As Single, n As Single
Dim Ultim As String
Dim a As Variant


m = 26
n = 1
Ultim = Left(Cells(1, 1).Value, 3)
Debug.Print (Ultim)


CantFila = Cells(Rows.Count, 2).End(xlUp).Row
CantCol = Cells(2, Columns.Count).End(xlToLeft).Column


For f = 1 To CantFila Step 1
    For c = 1 To CantCol Step 1

    If (Left(Cells(f, c).Value, 3) = Ultim) Then
        Debug.Print (Left(Cells(f, c).Value, 3))
        a = Cells(f, c).Value
        Cells(m, n).Value = a
        n = n + 1
        Ultim = Left(Cells(f, c).Value, 3)
    
    ElseIf ((Left(Cells(f, c).Value, 3) <> Ultim) And Left(Cells(f, c).Value, 3) = "") Then
        f = f + 1
        c = 1
        
        If (Left(Cells(f, c).Value, 3) = Ultim) Then
        a = Cells(f, c).Value
        Cells(m, n).Value = a
        n = n + 1
        Ultim = Left(Cells(f, c).Value, 3)
        End If
    
    Else
        
        m = m + 1
        n = 1
        a = Cells(f, c).Value
        Cells(m, n).Value = a
        Ultim = Left(Cells(f, c).Value, 3)
    
    End If

    Next c
Next f

End Sub












jueves, 28 de julio de 2022

como-bloquear-iphone-ipad-boton-encendido-roto

https://www.islabit.com/116608/como-bloquear-iphone-ipad-boton-encendido-roto.html

Cómo bloquear un iPhone o iPad con el botón de encendido roto

No es para nada agradable que el botón de encendido de nuestro dispositivo móvil no funcione, especialmente porque es fundamental para bloquear y desbloquear la pantalla. Sin embargo, los dispositivos de Apple cuentan con una opción bastante interesante para bloquear un iPhone o iPad si el botón de encendido está roto.

Estamos hablando de una función de accesibilidad llamada AssistiveTouch que nos permite simular movimientos, gestos y pulsaciones de botones con opciones de menú en la pantalla táctil. Esto es ideal porque en caso de tener el botón de encendido roto. Podemos apagar la pantalla del iPhone sin ninguna clase de problema.

Cómo bloquear iPhone con botón de encendido roto

Lo primero que deberemos hacer es dirigirnos a Configuración y luego tendremos que ir a Accesibilidad > Touch.


Cómo bloquear iPhone con botón de encendido roto

Lo primero que deberemos hacer es dirigirnos a Configuración y luego tendremos que ir a Accesibilidad > Touch.

En Configuración, vamos a Accesibilidad y Touch.

Ahora vamos a tener que pulsar en “AssistiveTouch”.

Podemos bloquear el teléfono con un botón virtual.

En esta nueva pantalla, tendremos que encender el interruptor que se encuentra junto a “AssistiveTouch”.

Activamos AssistiveTouch.

Ahora podremos ver que aparece un botón gris que tiene un círculo blanco en el medio. Aparecerá en un costado de la pantalla. Así es como logramos activar AssistiveTouch en iPhone.


viernes, 17 de junio de 2022

Colorear celdas en EXCEL (alternativo a Reglas)

 https://excelatfinance.com/xlf/xlf-colors-1.php


VBA colors


0. Quick guide to the RGB color model


In this module:

  1. RGB color circles
  2. ColorIndex property - 56 colours, and VBA ColorConstants
  3. RGB and decimal color values, plus conversion
  4. Color property

The RGB color model adds combinations of RedGreen, and Blue to produce various colours. Each component is an integer value 0 to 255. The RGB colors with intersection overlap is demonstrated in figure 1.


1. RGB colors


1.1 RGB circles with additive colour mixing


Three RGB circles with colour mixing - returns 7 colors.

rgb circles
Fig 1: - three circles; Red, Green, and Blue (RGB), with 4 intersection points

With the inclusion of black (no colour), the eight colours are:

  1. Black: RGB(0,0,0      
  2. White: RGB(255,255,255      

  3. Red: RGB(255,0,0      
  4. Green: RGB(0,255,0      
  5. Blue: RGB(0,0,255      

  6. Yellow: RGB(255,255,0      
  7. Magenta: RGB(255,0,255      
  8. Cyan: RGB(0,255,255      


1.2 RGB circles - production code


Using web browser CSS and Scalable Vector Graphics (SVG)



Code for CSS style and Scalable Vector Graphics (SVG) used to produce the RGB circles in figure 1
1
2
3
4
5
6
7
8
9
10
<style type="text/css">
    circle {mix-blend-mode: screen;}
</style>
 
<svg>
    <circle cx="75" cy="50" r="40" fill="rgb(255,0,0)"></circle>
    <circle cx="50" cy="100" r="40" fill="rgb(0,255,0)"></circle>
    <circle cx="100" cy="100" r="40" fill="rgb(0,0,255)"></circle>
</svg>
    


2. VBA ColorIndex property


Syntax: expression.ColorIndex = value


where value is an element from the integer series 1,2, …, 56. Special values include xlColorIndexAutomatic (-4105) and xlColorIndexNone (-4142).


Examples of the ColorIndex property:

  • xlRange.Value = "excel"
  • xlRange.Interior.ColorIndex = 48
  • xlRange.Font.ColorIndex = 20
  • xlRange.Borders.ColorIndex = 3
  • xlRange.Characters(1, 2).Font.ColorIndex = 6


2.1 The 56 colours of ColorIndex


Colours 2 to 8 are red, green, and blue with additive mixing. The colours 9 to 56 are various combinations of red, green and blue with RGB values: 0, 51, 102, 128, 150, 153, 192, 204, and 255 (figure 2).


xlf-colindx2ws
Fig 2: ColorIndex - numbers, colours, and RGB values from code 1



The WS range in figure 2 was printed from the ColIndx2wWS procedure in code 1.



Code 1: Sub ColIndx2WS procedure prints ColorIndex to WS (see figure 2)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Sub ColIndx2WS()
' Requires xlfDec2RGB(ColDec) function
Dim i As Integer
Dim AC As Range: Set AC = ActiveCell
 
    For i = 1 To 56
        AC(i, 1) = i
        AC(i, 1).HorizontalAlignment = xlLeft
        AC(i, 2).Interior.ColorIndex = i
        AC(i, 3).Value = "RGB(" & xlfDec2RGB(AC(i, 2).Interior.Color) & ")"     ' see code ...
        AC(i, 3).HorizontalAlignment = xlRight
    Next i
    AC(i, 3).ColumnWidth = 19
End Sub



The colour table can also be printed as a 7 by 8 array (code 2)


Fig 3: - VBA ColorIndex 56 colors, 7 x 8 array



Code 2: Sub ColIndx2WSarraS procedure prints ColorIndex to WS array (7 rows by 8 columns)
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Sub ColIndx2WSarray()
Const TLC As String = "B2"      ' top left cell
Dim i As Integer, j As Integer
Dim Col As Integer, Val As Integer
 
    With Range(TLC)
    For i = 1 To 7
        For j = 1 To 8
            Col = i * j
            Val = Val + 1
            .Offset(i - 1, j - 1).Interior.ColorIndex = Col
            .Offset(i - 1, j - 1).Value = Val
            Select Case Col
                Case 1, 5, 9 To 14, 16, 18, 21, 23, 25, 29, 30, 32, 41, 47 To 49, 51 To 56
                    .Offset(i - 1, j - 1).Font.ColorIndex = 2
                Case Else
                    .Offset(i - 1, j - 1).Font.ColorIndex = 1
            End Select
        Next j
    Next i
        .Resize(7, 8).ColumnWidth = 5
        .Resize(7, 8).RowHeight = 20
    End With
 
End Sub


Ten of the ColorIndex colours are duplicate pairs: Blue    5    and    32   Yellow    6    and    27   Pink    7    and    26   Turquoise    8    and    28   Dark Red    9    and    30   Dark Blue    11    and    25   Violet    13    and    29   Teal    14    and    31   [No name]    18    and    54   ; and [No name]    20    and    34    . Leaving only 46 unique colours.


2.2 ColorConstants


The 8 colours listed in section 1.1 have name equivalents listed as members of the VBA ColorConstants class in the decimal colour system. The ColorConstants Auto List drop down is shown in figure 4.


media/xlf-vba-colorconstants
Fig 4: VBA ColorConstants - VBA Auto List drop down with 8 items


Code 3 prints a list of the ColorConstants numerical values to the immediate window (figure 5).



Code 3: Sub ColConst procedure
60
61
62
63
64
65
66
67
68
69
70
71
72
Sub ColConst()
Dim i As Integer
Dim ColArrVal As Variant
Dim ColArrLbl As Variant
 
    ColArrVal = Array(vbBlack, vbWhite, vbRed, vbGreen, vbBlue, vbYellow, vbMagenta, vbCyan)
    ColArrLbl = Array("vbBlack", "vbWhite", "vbRed", "vbGreen", "vbBlue", "vbYellow", "vbMagenta", "vbCyan")
 
    For i = LBound(ColArrVal) To UBound(ColArrVal)
        Debug.Print ColArrLbl(i) & ": " & ColArrVal(i)
    Next i
 
End Sub
The immediate window with output from line 69
media/xlf-colorconstants-decimal
Fig 5: VBA ColorConstants - colors 1 to 8


3. Decimal values of colours


3.1 RGB to positive decimal


To convert RGB to decimal , the relationship is Cd=R2560+(G2561)+(B2562). See code 4.



Code 4: Function xlfRGB2DecX converts RGB values to decimal. Includes test routine
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Function xlfRGB2DecX(Red As Integer, Green As Integer, Blue As Integer) As Long
    xlfRGB2DecX = Red * 256 ^ 0 + Green * 256 ^ 1 + Blue * 256 ^ 2
End Function
 
' ===========================
Function xlfRGB2DecY(Red As Integer, Green As Integer, Blue As Integer) As Long
    xlfRGB2DecY = RGB(Red, Green, Blue)
End Function
 
' ===========================
Sub TestxlfRGB2DecX()
Dim Ans As Long
    Ans = xlfRGB2DecX(204, 255, 255)
End Sub


3.2 RGB to negative decimal


To convert RGB to Excel negative decimal, the relationship is Cd=RGB(2563)1


The color red is RGB(255,0,0), equal to 256 as a positive value. The Excel negative value equivalent is RGB - (256^3) - 1 = 256 - (256^3) - 1 = -16776961


3.3 Decimal to RGB


The backslash operator "\" divides two numbers and returns the integer quotient. The remainder is ignored.



Code 5: Function xlfDec2RGB converts color decimal to RGB comma separated values. Includes test routine
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
Function xlfDec2RGB(ByVal ColDec As Long) As String
Dim R As Long
Dim G As Long
Dim b As Long
 
  R = (ColDec And &HFF) \ 256 ^ 0      ' &HFF hexadecimal = 255 decimal
                                       ' leading &H is the prefix radix (base) for hexadecimal
  G = (ColDec And &HFF00&) \ 256 ^ 1   ' &HFF00& hexadecimal = 65280 decimal
                                       ' trailing & is a TDC for type long, if
                                       ' omitted (&HFF00), the assigned value is -256
  b = ColDec \ 256 ^ 2
  xlfDec2RGB = CStr(R) & "," & CStr(G) & "," & CStr(b)
 
End Function
 
' ===========================
Sub TestxlfDec2RGB()
Dim Ans As String
    Ans = xlfDec2RGB(16737843)  ' returns 51,102,255
    Stop
End Sub


About code 5

  • Line 95: 16737843 And 255 returns 51, 51 \ 1 returns 51, remainder 0
    Further details of the binary And are provided in figure 5. Only the last 8 digits on the right are relevant.
    • 16737843 = 111111110110011000110011;
    • 255 = 11111111;
    • AND returns 00110011 = 51
  • xlf-binary-and
    Fig 5: binary AND - last 8 digits on the right
  • Line 97: 16737843 And 65280 returns 26112, 26112 \ 256 returns 102, remainder 0
  • Line 100: 16737843 \ 65536 returns 255, remainder 2616


4. Color property


Syntax: expression.Color = value


where value can be created by the RGB function returned as a long whole number.


Examples of the Color property:

  • xlRange.Value = "excel"
  • xlRange.Interior.Color = RGB(150,150,150) (equivalent to ColorIndex 48)
  • xlRange.Font.Color = 16777164 (equivalent to: RGB(204,255,255); ColorIndex 48)
  • xlRange.Borders.Color = RGB(150,0,0) (equivalent to ColorIndex 3)
  • xlRange.Characters(1, 2).Font.Color = 6 (equivalent to: RGB(6,0,0))



  • RGB discussion [23 Apr 2018]

  • Development platform: Excel 2016 64 bit.
  • Published: 14th April 2016
  • Revised: Monday 28th of January 2019 - 10:28 PM, Pacific Time (PT)